mirror of
https://github.com/qbittorrent/qBittorrent
synced 2025-08-20 21:33:27 -07:00
Revise command-line show message condition
Now when user specified 'help' or 'version' flag, the program will process them first and ignore all other flags (even invalid flags). This improves program usability since user will be able to consult the help description without ensuring existing flags are all valid (or removing all flags). And user can refine the flags after reading the help description.
This commit is contained in:
parent
bb1c02125b
commit
9aebb66dd4
1 changed files with 15 additions and 25 deletions
|
@ -182,9 +182,6 @@ int main(int argc, char *argv[])
|
||||||
adjustFileDescriptorLimit();
|
adjustFileDescriptorLimit();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// We must save it here because QApplication constructor may change it
|
|
||||||
const bool isOneArg = (argc == 2);
|
|
||||||
|
|
||||||
// `app` must be declared out of try block to allow display message box in case of exception
|
// `app` must be declared out of try block to allow display message box in case of exception
|
||||||
std::unique_ptr<Application> app;
|
std::unique_ptr<Application> app;
|
||||||
try
|
try
|
||||||
|
@ -204,34 +201,27 @@ int main(int argc, char *argv[])
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
const QBtCommandLineParameters params = app->commandLineArgs();
|
const QBtCommandLineParameters params = app->commandLineArgs();
|
||||||
|
|
||||||
|
// "show help/version" takes priority over other flags
|
||||||
|
if (params.showHelp)
|
||||||
|
{
|
||||||
|
displayUsage(QString::fromLocal8Bit(argv[0]));
|
||||||
|
return EXIT_SUCCESS;
|
||||||
|
}
|
||||||
|
#if !defined(Q_OS_WIN) || defined(DISABLE_GUI)
|
||||||
|
if (params.showVersion)
|
||||||
|
{
|
||||||
|
displayVersion();
|
||||||
|
return EXIT_SUCCESS;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
if (!params.unknownParameter.isEmpty())
|
if (!params.unknownParameter.isEmpty())
|
||||||
{
|
{
|
||||||
throw CommandLineParameterError(QCoreApplication::translate("Main", "%1 is an unknown command line parameter.",
|
throw CommandLineParameterError(QCoreApplication::translate("Main", "%1 is an unknown command line parameter.",
|
||||||
"--random-parameter is an unknown command line parameter.")
|
"--random-parameter is an unknown command line parameter.")
|
||||||
.arg(params.unknownParameter));
|
.arg(params.unknownParameter));
|
||||||
}
|
}
|
||||||
#if !defined(Q_OS_WIN) || defined(DISABLE_GUI)
|
|
||||||
if (params.showVersion)
|
|
||||||
{
|
|
||||||
if (isOneArg)
|
|
||||||
{
|
|
||||||
displayVersion();
|
|
||||||
return EXIT_SUCCESS;
|
|
||||||
}
|
|
||||||
throw CommandLineParameterError(QCoreApplication::translate("Main", "%1 must be the single command line parameter.")
|
|
||||||
.arg(u"-v (or --version)"_s));
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
if (params.showHelp)
|
|
||||||
{
|
|
||||||
if (isOneArg)
|
|
||||||
{
|
|
||||||
displayUsage(QString::fromLocal8Bit(argv[0]));
|
|
||||||
return EXIT_SUCCESS;
|
|
||||||
}
|
|
||||||
throw CommandLineParameterError(QCoreApplication::translate("Main", "%1 must be the single command line parameter.")
|
|
||||||
.arg(u"-h (or --help)"_s));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check if qBittorrent is already running
|
// Check if qBittorrent is already running
|
||||||
if (app->hasAnotherInstance())
|
if (app->hasAnotherInstance())
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue