From 85ba998551cf0ffb2ed9b059758fbdc9c28d1b92 Mon Sep 17 00:00:00 2001 From: louib Date: Sat, 4 Jan 2020 16:23:23 -0500 Subject: [PATCH] Use stderr for help text on error. Also not sure why qCritical was used instead of and stderr output stream. Added translation on the invalid command string. --- src/cli/keepassxc-cli.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/cli/keepassxc-cli.cpp b/src/cli/keepassxc-cli.cpp index 179b79a435..85351e61db 100644 --- a/src/cli/keepassxc-cli.cpp +++ b/src/cli/keepassxc-cli.cpp @@ -189,6 +189,7 @@ int main(int argc, char** argv) Commands::setupCommands(false); TextStream out(stdout); + TextStream err(stderr); QStringList arguments; for (int i = 0; i < argc; ++i) { arguments << QString(argv[i]); @@ -223,6 +224,7 @@ int main(int argc, char** argv) out << debugInfo << endl; return EXIT_SUCCESS; } + // showHelp exits the application immediately. parser.showHelp(); } @@ -234,10 +236,9 @@ int main(int argc, char** argv) auto command = Commands::getCommand(commandName); if (!command) { - qCritical("Invalid command %s.", qPrintable(commandName)); - // showHelp exits the application immediately, so we need to set the - // exit code here. - parser.showHelp(EXIT_FAILURE); + err << QObject::tr("Invalid command %1.").arg(commandName) << endl; + err << parser.helpText(); + return EXIT_FAILURE; } // Removing the first argument (keepassxc).