mirror of
https://github.com/keepassxreboot/keepassxc.git
synced 2026-01-06 02:55:43 -05:00
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:
parent
d09ca076dc
commit
726bbb2d94
12 changed files with 80 additions and 82 deletions
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue