mirror of
https://github.com/moonlight-stream/moonlight-qt.git
synced 2025-07-02 15:55:39 +00:00
Fix parsing CLI flags that accept values when passed before 'action' argument
This commit is contained in:
parent
5b6142e2d9
commit
b282c7d815
@ -172,20 +172,31 @@ GlobalCommandLineParser::ParseResult GlobalCommandLineParser::parse(const QStrin
|
|||||||
parser.addPositionalArgument("action", "Action to execute", "<action>");
|
parser.addPositionalArgument("action", "Action to execute", "<action>");
|
||||||
parser.parse(args);
|
parser.parse(args);
|
||||||
auto posArgs = parser.positionalArguments();
|
auto posArgs = parser.positionalArguments();
|
||||||
QString action = posArgs.isEmpty() ? QString() : posArgs.first().toLower();
|
|
||||||
|
|
||||||
if (action == "") {
|
if (posArgs.isEmpty()) {
|
||||||
// This method will not return and terminates the process if --version
|
// This method will not return and terminates the process if --version
|
||||||
// or --help is specified
|
// or --help is specified
|
||||||
parser.handleHelpAndVersionOptions();
|
parser.handleHelpAndVersionOptions();
|
||||||
parser.handleUnknownOptions();
|
parser.handleUnknownOptions();
|
||||||
return NormalStartRequested;
|
return NormalStartRequested;
|
||||||
} else if (action == "quit") {
|
}
|
||||||
return QuitRequested;
|
else {
|
||||||
} else if (action == "stream") {
|
// If users supply arguments that accept values prior to the "quit"
|
||||||
return StreamRequested;
|
// or "stream" positional arguments, we will not be able to correctly
|
||||||
} else {
|
// parse the value out of the input because this QCommandLineParser
|
||||||
parser.showError(QString("Invalid action: %1").arg(action));
|
// doesn't know about all of the options that "quit" and "stream"
|
||||||
|
// commands can accept. To work around this issue, we just look
|
||||||
|
// for "quit" or "stream" positional arguments anywhere.
|
||||||
|
for (int i = 0; i < posArgs.size(); i++) {
|
||||||
|
QString action = posArgs.at(i).toLower();
|
||||||
|
if (action == "quit") {
|
||||||
|
return QuitRequested;
|
||||||
|
} else if (action == "stream") {
|
||||||
|
return StreamRequested;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
parser.showError(QString("Invalid action"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user