Skip to content

Commit

Permalink
Use stderr for help text on error.
Browse files Browse the repository at this point in the history
Also not sure why qCritical was used instead of and stderr output
stream. Added translation on the invalid command string.
  • Loading branch information
louib authored and louib committed Jan 4, 2020
1 parent 62cda9d commit 85ba998
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/cli/keepassxc-cli.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand Down Expand Up @@ -223,6 +224,7 @@ int main(int argc, char** argv)
out << debugInfo << endl;
return EXIT_SUCCESS;
}
// showHelp exits the application immediately.
parser.showHelp();
}

Expand All @@ -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).
Expand Down

0 comments on commit 85ba998

Please sign in to comment.