Skip to content

Commit

Permalink
Allow for command options with one name
Browse files Browse the repository at this point in the history
For options with more than one name, the long/formal name should come
last.
  • Loading branch information
oblivioncth committed Nov 2, 2023
1 parent eee5b4f commit 0acd5b7
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion app/src/command/command.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ CommandError Command::parse(const QStringList& commandLine)
if(!optionsStr.isEmpty())
optionsStr += ' '; // Space after every switch except first one

optionsStr += u"--"_s + (*clOption).names().at(1); // Always use long name
optionsStr += u"--"_s + (*clOption).names().constLast(); // Always use long name

// Add value of switch if it takes one
if(!(*clOption).valueName().isEmpty())
Expand Down
4 changes: 2 additions & 2 deletions app/src/command/command.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,12 @@ class Command

// Standard command line option strings
static inline const QString CL_OPT_HELP_S_NAME = u"h"_s;
static inline const QString CL_OPT_HELP_L_NAME = u"help"_s;
static inline const QString CL_OPT_HELP_E_NAME = u"?"_s;
static inline const QString CL_OPT_HELP_L_NAME = u"help"_s;
static inline const QString CL_OPT_HELP_DESC = u"Prints this help message."_s;

// Standard command line options
static inline const QCommandLineOption CL_OPTION_HELP{{CL_OPT_HELP_S_NAME, CL_OPT_HELP_L_NAME, CL_OPT_HELP_E_NAME}, CL_OPT_HELP_DESC}; // Boolean option
static inline const QCommandLineOption CL_OPTION_HELP{{CL_OPT_HELP_S_NAME, CL_OPT_HELP_E_NAME, CL_OPT_HELP_L_NAME}, CL_OPT_HELP_DESC}; // Boolean option
static inline const QList<const QCommandLineOption*> CL_OPTIONS_STANDARD{&CL_OPTION_HELP};

// Meta
Expand Down
2 changes: 1 addition & 1 deletion app/src/kernel/core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ Qx::Error Core::initialize(QStringList& commandLine)
if(!globalOptions.isEmpty())
globalOptions += ' '; // Space after every switch except first one

globalOptions += u"--"_s + (*clOption).names().at(1); // Always use long name
globalOptions += u"--"_s + (*clOption).names().constLast(); // Always use long name

// Add value of switch if it takes one
if(!(*clOption).valueName().isEmpty())
Expand Down
4 changes: 2 additions & 2 deletions app/src/kernel/core.h
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,8 @@ class Core : public QObject

// Global command line option strings
static inline const QString CL_OPT_HELP_S_NAME = u"h"_s;
static inline const QString CL_OPT_HELP_L_NAME = u"help"_s;
static inline const QString CL_OPT_HELP_E_NAME = u"?"_s;
static inline const QString CL_OPT_HELP_L_NAME = u"help"_s;
static inline const QString CL_OPT_HELP_DESC = u"Prints this help message."_s;

static inline const QString CL_OPT_VERSION_S_NAME = u"v"_s;
Expand All @@ -191,7 +191,7 @@ class Core : public QObject
static inline const QString CL_OPT_SILENT_DESC = u"Silences all messages (takes precedence over quiet mode)."_s;

// Global command line options
static inline const QCommandLineOption CL_OPTION_HELP{{CL_OPT_HELP_S_NAME, CL_OPT_HELP_L_NAME, CL_OPT_HELP_E_NAME}, CL_OPT_HELP_DESC}; // Boolean option
static inline const QCommandLineOption CL_OPTION_HELP{{CL_OPT_HELP_S_NAME, CL_OPT_HELP_E_NAME, CL_OPT_HELP_L_NAME}, CL_OPT_HELP_DESC}; // Boolean option
static inline const QCommandLineOption CL_OPTION_VERSION{{CL_OPT_VERSION_S_NAME, CL_OPT_VERSION_L_NAME}, CL_OPT_VERSION_DESC}; // Boolean option
static inline const QCommandLineOption CL_OPTION_QUIET{{CL_OPT_QUIET_S_NAME, CL_OPT_QUIET_L_NAME}, CL_OPT_QUIET_DESC}; // Boolean option
static inline const QCommandLineOption CL_OPTION_SILENT{{CL_OPT_SILENT_S_NAME, CL_OPT_SILENT_L_NAME}, CL_OPT_SILENT_DESC}; // Boolean option
Expand Down

0 comments on commit 0acd5b7

Please sign in to comment.