We should output to stderr on EXIT_FAILURE (#2558)

Making sure we use stderr to output the help
message when there is an invalid number of
arguments, or when there's any error related
to the arguments.
This commit is contained in:
louib 2019-01-16 12:32:06 -05:00 committed by Jonathan White
parent d09ca076dc
commit 726bbb2d94
12 changed files with 80 additions and 82 deletions

View file

@ -40,7 +40,7 @@ List::~List()
int List::execute(const QStringList& arguments)
{
TextStream out(Utils::STDOUT);
TextStream errorTextStream(Utils::STDERR, QIODevice::WriteOnly);
QCommandLineParser parser;
parser.setApplicationDescription(description);
@ -58,7 +58,7 @@ int List::execute(const QStringList& arguments)
const QStringList args = parser.positionalArguments();
if (args.size() != 1 && args.size() != 2) {
out << parser.helpText().replace("keepassxc-cli", "keepassxc-cli ls");
errorTextStream << parser.helpText().replace("keepassxc-cli", "keepassxc-cli ls");
return EXIT_FAILURE;
}
@ -80,20 +80,20 @@ int List::execute(const QStringList& arguments)
int List::listGroup(Database* database, bool recursive, const QString& groupPath)
{
TextStream out(Utils::STDOUT, QIODevice::WriteOnly);
TextStream err(Utils::STDERR, QIODevice::WriteOnly);
TextStream outputTextStream(Utils::STDOUT, QIODevice::WriteOnly);
TextStream errorTextStream(Utils::STDERR, QIODevice::WriteOnly);
if (groupPath.isEmpty()) {
out << database->rootGroup()->print(recursive) << flush;
outputTextStream << database->rootGroup()->print(recursive) << flush;
return EXIT_SUCCESS;
}
Group* group = database->rootGroup()->findGroupByPath(groupPath);
if (!group) {
err << QObject::tr("Cannot find group %1.").arg(groupPath) << endl;
errorTextStream << QObject::tr("Cannot find group %1.").arg(groupPath) << endl;
return EXIT_FAILURE;
}
out << group->print(recursive) << flush;
outputTextStream << group->print(recursive) << flush;
return EXIT_SUCCESS;
}