!chore: refactor -n command line option

This commit is contained in:
august-alt 2022-11-23 15:36:09 +04:00
parent e601430ce1
commit fc90e275bd
3 changed files with 28 additions and 39 deletions

View File

@ -16,8 +16,7 @@ Provide the full path of the policy to edit.
Provide the path of admx files to load. Provide the path of admx files to load.
.TP .TP
.if !'po4a'hide' .BR \-n .if !'po4a'hide' .BR \-n
The parameter to be used in conjunction with ADMC, allows ADMC to pass the name of the GPO which will be used in Parameters provides compatibilty with ADMC, currently it performs no specific function.
a window title.
.TP .TP
.if !'po4a'hide' .BR \-h ", " \-\-help .if !'po4a'hide' .BR \-h ", " \-\-help
Show help message and exit program. Show help message and exit program.

View File

@ -16,7 +16,7 @@ gpui-main это программа для управления шаблонам
Позволяет указать путь для загрузки admx файлов. Позволяет указать путь для загрузки admx файлов.
.TP .TP
.if !'po4a'hide' .BR \-n .if !'po4a'hide' .BR \-n
Параметр для использования совместно с ADMC, позволяет ADMC передать имя GPO для отображения. Параметр оставлен для обеспечения обраной совместимости с ADMC. Он никак не влияет на работу приложения.
.TP .TP
.if !'po4a'hide' .BR \-h ", " \-\-help .if !'po4a'hide' .BR \-h ", " \-\-help
Показать справочное сообщение и закончить работу. Показать справочное сообщение и закончить работу.

View File

@ -22,44 +22,42 @@
#include <memory> #include <memory>
#include <QUuid>
#include <QCommandLineParser> #include <QCommandLineParser>
#include <QTranslator>
#include <QLibraryInfo> #include <QLibraryInfo>
#include <QTranslator>
#include <QUuid>
namespace gpui namespace gpui
{ {
class CommandLineParserPrivate class CommandLineParserPrivate
{ {
public: public:
QApplication& application; QApplication &application;
std::unique_ptr<QCommandLineParser> parser; std::unique_ptr<QCommandLineParser> parser;
CommandLineParserPrivate(QApplication &currentApplication) CommandLineParserPrivate(QApplication &currentApplication)
: application(currentApplication) : application(currentApplication)
, parser(std::make_unique<QCommandLineParser>()) , parser(std::make_unique<QCommandLineParser>())
{ {}
}
private: private:
CommandLineParserPrivate(const CommandLineParserPrivate&) = delete; // copy ctor CommandLineParserPrivate(const CommandLineParserPrivate &) = delete; // copy ctor
CommandLineParserPrivate(CommandLineParserPrivate&&) = delete; // move ctor CommandLineParserPrivate(CommandLineParserPrivate &&) = delete; // move ctor
CommandLineParserPrivate& operator=(const CommandLineParserPrivate&) = delete; // copy assignment CommandLineParserPrivate &operator=(const CommandLineParserPrivate &) = delete; // copy assignment
CommandLineParserPrivate& operator=(CommandLineParserPrivate&&) = delete; // move assignment CommandLineParserPrivate &operator=(CommandLineParserPrivate &&) = delete; // move assignment
}; };
CommandLineParser::CommandLineParser(QApplication &application) CommandLineParser::CommandLineParser(QApplication &application)
: d(new CommandLineParserPrivate(application)) : d(new CommandLineParserPrivate(application))
{ {}
}
CommandLineParser::~CommandLineParser() CommandLineParser::~CommandLineParser()
{ {
delete d; delete d;
} }
CommandLineParser::CommandLineParseResult CommandLineParser::parseCommandLine(CommandLineOptions *options, QString *errorMessage) CommandLineParser::CommandLineParseResult CommandLineParser::parseCommandLine(CommandLineOptions *options,
QString *errorMessage)
{ {
QLocale locale; QLocale locale;
std::unique_ptr<QTranslator> qtTranslator = std::make_unique<QTranslator>(); std::unique_ptr<QTranslator> qtTranslator = std::make_unique<QTranslator>();
@ -71,14 +69,19 @@ CommandLineParser::CommandLineParseResult CommandLineParser::parseCommandLine(Co
QCoreApplication::installTranslator(qtTranslator2.get()); QCoreApplication::installTranslator(qtTranslator2.get());
const QCommandLineOption pathOption("p", QObject::tr("The full path of policy to edit."), QObject::tr("path")); const QCommandLineOption pathOption("p", QObject::tr("The full path of policy to edit."), QObject::tr("path"));
const QCommandLineOption bundleOption("b", QObject::tr("The full path of policy bundle to load."), QObject::tr("path")); const QCommandLineOption bundleOption("b",
const QCommandLineOption nameOption("n", QObject::tr("The name of a policy to display."), QObject::tr("name")); QObject::tr("The full path of policy bundle to load."),
QObject::tr("path"));
const QCommandLineOption nameOption("n",
QObject::tr("This options left for compatibility with ADMC. "
"Currently it does nothing."),
QObject::tr("name"));
const QCommandLineOption helpOption(QStringList() const QCommandLineOption helpOption(QStringList()
#ifdef Q_OS_WIN #ifdef Q_OS_WIN
<< QStringLiteral("?") << QStringLiteral("?")
#endif #endif
<< QStringLiteral("h") << QStringLiteral("h") << QStringLiteral("help"),
<< QStringLiteral("help"), QObject::tr("Displays help on commandline options.")); QObject::tr("Displays help on commandline options."));
d->parser->setSingleDashWordOptionMode(QCommandLineParser::ParseAsLongOptions); d->parser->setSingleDashWordOptionMode(QCommandLineParser::ParseAsLongOptions);
d->parser->addOption(pathOption); d->parser->addOption(pathOption);
@ -128,19 +131,6 @@ CommandLineParser::CommandLineParseResult CommandLineParser::parseCommandLine(Co
} }
} }
if (d->parser->isSet(nameOption))
{
const QString name = d->parser->value(nameOption);
options->policyName = name;
if (options->policyName.isNull() || options->policyName.isEmpty())
{
*errorMessage = QObject::tr("Bad policy name: ") + name;
return CommandLineError;
}
}
return CommandLineOk; return CommandLineOk;
} }
@ -154,4 +144,4 @@ void CommandLineParser::showVersion() const
d->parser->showVersion(); d->parser->showVersion();
} }
} } // namespace gpui