!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.
.TP
.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
a window title.
Parameters provides compatibilty with ADMC, currently it performs no specific function.
.TP
.if !'po4a'hide' .BR \-h ", " \-\-help
Show help message and exit program.

View File

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

View File

@ -22,44 +22,42 @@
#include <memory>
#include <QUuid>
#include <QCommandLineParser>
#include <QTranslator>
#include <QLibraryInfo>
#include <QTranslator>
#include <QUuid>
namespace gpui
{
class CommandLineParserPrivate
{
public:
QApplication& application;
QApplication &application;
std::unique_ptr<QCommandLineParser> parser;
CommandLineParserPrivate(QApplication &currentApplication)
: application(currentApplication)
, parser(std::make_unique<QCommandLineParser>())
{
}
{}
private:
CommandLineParserPrivate(const CommandLineParserPrivate&) = delete; // copy ctor
CommandLineParserPrivate(CommandLineParserPrivate&&) = delete; // move ctor
CommandLineParserPrivate& operator=(const CommandLineParserPrivate&) = delete; // copy assignment
CommandLineParserPrivate& operator=(CommandLineParserPrivate&&) = delete; // move assignment
CommandLineParserPrivate(const CommandLineParserPrivate &) = delete; // copy ctor
CommandLineParserPrivate(CommandLineParserPrivate &&) = delete; // move ctor
CommandLineParserPrivate &operator=(const CommandLineParserPrivate &) = delete; // copy assignment
CommandLineParserPrivate &operator=(CommandLineParserPrivate &&) = delete; // move assignment
};
CommandLineParser::CommandLineParser(QApplication &application)
: d(new CommandLineParserPrivate(application))
{
}
{}
CommandLineParser::~CommandLineParser()
{
delete d;
}
CommandLineParser::CommandLineParseResult CommandLineParser::parseCommandLine(CommandLineOptions *options, QString *errorMessage)
CommandLineParser::CommandLineParseResult CommandLineParser::parseCommandLine(CommandLineOptions *options,
QString *errorMessage)
{
QLocale locale;
std::unique_ptr<QTranslator> qtTranslator = std::make_unique<QTranslator>();
@ -71,14 +69,19 @@ CommandLineParser::CommandLineParseResult CommandLineParser::parseCommandLine(Co
QCoreApplication::installTranslator(qtTranslator2.get());
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 nameOption("n", QObject::tr("The name of a policy to display."), QObject::tr("name"));
const QCommandLineOption bundleOption("b",
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()
#ifdef Q_OS_WIN
<< QStringLiteral("?")
#endif
<< QStringLiteral("h")
<< QStringLiteral("help"), QObject::tr("Displays help on commandline options."));
#ifdef Q_OS_WIN
<< QStringLiteral("?")
#endif
<< QStringLiteral("h") << QStringLiteral("help"),
QObject::tr("Displays help on commandline options."));
d->parser->setSingleDashWordOptionMode(QCommandLineParser::ParseAsLongOptions);
d->parser->addOption(pathOption);
@ -107,7 +110,7 @@ CommandLineParser::CommandLineParseResult CommandLineParser::parseCommandLine(Co
if (d->parser->isSet(pathOption))
{
const QString path = d->parser->value(pathOption);
options->path = path;
options->path = path;
if (options->path.isNull() || options->path.isEmpty())
{
@ -118,7 +121,7 @@ CommandLineParser::CommandLineParseResult CommandLineParser::parseCommandLine(Co
if (d->parser->isSet(bundleOption))
{
const QString path = d->parser->value(bundleOption);
const QString path = d->parser->value(bundleOption);
options->policyBundle = path;
if (options->policyBundle.isNull() || options->policyBundle.isEmpty())
@ -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;
}
@ -154,4 +144,4 @@ void CommandLineParser::showVersion() const
d->parser->showVersion();
}
}
} // namespace gpui