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 authored and Jonathan White committed 2019-01-16 12:32:06 -05:00
1 parent d09ca076dc
commit 726bbb2d94
12 files changed
+80 -82

No files matched your search

+5 -5
View File
@@ -38,8 +38,8 @@ Generate::~Generate()
int Generate::execute(const QStringList& arguments)
{
TextStream in(Utils::STDIN, QIODevice::ReadOnly);
TextStream out(Utils::STDOUT, QIODevice::WriteOnly);
TextStream outputTextStream(Utils::STDOUT, QIODevice::WriteOnly);
TextStream errorTextStream(Utils::STDERR, QIODevice::WriteOnly);
QCommandLineParser parser;
parser.setApplicationDescription(description);
@@ -84,7 +84,7 @@ int Generate::execute(const QStringList& arguments)
const QStringList args = parser.positionalArguments();
if (!args.isEmpty()) {
out << parser.helpText().replace("keepassxc-cli", "keepassxc-cli generate");
errorTextStream << parser.helpText().replace("keepassxc-cli", "keepassxc-cli generate");
return EXIT_FAILURE;
}
@@ -128,12 +128,12 @@ int Generate::execute(const QStringList& arguments)
passwordGenerator.setExcludedChars(parser.value(exclude));
if (!passwordGenerator.isValid()) {
out << parser.helpText().replace("keepassxc-cli", "keepassxc-cli generate");
errorTextStream << parser.helpText().replace("keepassxc-cli", "keepassxc-cli generate");
return EXIT_FAILURE;
}
QString password = passwordGenerator.generatePassword();
out << password << endl;
outputTextStream << password << endl;
return EXIT_SUCCESS;
}