diff --git a/src/cli/Add.cpp b/src/cli/Add.cpp index 5c97299b82..6df23a2855 100644 --- a/src/cli/Add.cpp +++ b/src/cli/Add.cpp @@ -43,7 +43,7 @@ int Add::execute(const QStringList& arguments) { QTextStream inputTextStream(stdin, QIODevice::ReadOnly); - QTextStream outputTextStream(stdout, QIODevice::WriteOnly); + QTextStream errorTextStream(stderr, QIODevice::WriteOnly); QCommandLineParser parser; parser.setApplicationDescription(this->description); @@ -85,7 +85,7 @@ int Add::execute(const QStringList& arguments) const QStringList args = parser.positionalArguments(); if (args.size() != 2) { - outputTextStream << parser.helpText().replace("keepassxc-cli", "keepassxc-cli add"); + errorTextStream << parser.helpText().replace("keepassxc-cli", "keepassxc-cli add"); return EXIT_FAILURE; } @@ -120,8 +120,8 @@ int Add::execute(const QStringList& arguments) } if (parser.isSet(prompt)) { - outputTextStream << "Enter password for new entry: "; - outputTextStream.flush(); + errorTextStream << "Enter password for new entry: "; + errorTextStream.flush(); QString password = Utils::getPassword(); entry->setPassword(password); } else if (parser.isSet(generate)) { @@ -145,6 +145,6 @@ int Add::execute(const QStringList& arguments) return EXIT_FAILURE; } - outputTextStream << "Successfully added entry " << entry->title() << "." << endl; + errorTextStream << "Successfully added entry " << entry->title() << "." << endl; return EXIT_SUCCESS; } diff --git a/src/cli/Clip.cpp b/src/cli/Clip.cpp index 886f8ecc71..40ac112395 100644 --- a/src/cli/Clip.cpp +++ b/src/cli/Clip.cpp @@ -43,7 +43,7 @@ Clip::~Clip() int Clip::execute(const QStringList& arguments) { - QTextStream out(stdout); + QTextStream errorTextStream(stderr); QCommandLineParser parser; parser.setApplicationDescription(this->description); @@ -60,7 +60,7 @@ int Clip::execute(const QStringList& arguments) const QStringList args = parser.positionalArguments(); if (args.size() != 2 && args.size() != 3) { - out << parser.helpText().replace("keepassxc-cli", "keepassxc-cli clip"); + errorTextStream << parser.helpText().replace("keepassxc-cli", "keepassxc-cli clip"); return EXIT_FAILURE; } @@ -83,7 +83,7 @@ int Clip::clipEntry(Database* database, QString entryPath, QString timeout) timeoutSeconds = timeout.toInt(); } - QTextStream outputTextStream(stdout, QIODevice::WriteOnly); + QTextStream errorTextStream(stderr, QIODevice::WriteOnly); Entry* entry = database->rootGroup()->findEntry(entryPath); if (!entry) { qCritical("Entry %s not found.", qPrintable(entryPath)); @@ -95,20 +95,20 @@ int Clip::clipEntry(Database* database, QString entryPath, QString timeout) return exitCode; } - outputTextStream << "Entry's password copied to the clipboard!" << endl; + errorTextStream << "Entry's password copied to the clipboard!" << endl; if (!timeoutSeconds) { return exitCode; } while (timeoutSeconds > 0) { - outputTextStream << "\rClearing the clipboard in " << timeoutSeconds << " seconds..."; - outputTextStream.flush(); + errorTextStream << "\rClearing the clipboard in " << timeoutSeconds << " seconds..."; + errorTextStream.flush(); std::this_thread::sleep_for(std::chrono::milliseconds(1000)); timeoutSeconds--; } Utils::clipText(""); - outputTextStream << "\nClipboard cleared!" << endl; + errorTextStream << "\nClipboard cleared!" << endl; return EXIT_SUCCESS; } diff --git a/src/cli/Diceware.cpp b/src/cli/Diceware.cpp index 4cdda0a73a..4663e51894 100644 --- a/src/cli/Diceware.cpp +++ b/src/cli/Diceware.cpp @@ -39,6 +39,7 @@ int Diceware::execute(const QStringList& arguments) { QTextStream inputTextStream(stdin, QIODevice::ReadOnly); QTextStream outputTextStream(stdout, QIODevice::WriteOnly); + QTextStream errorTextStream(stderr, QIODevice::WriteOnly); QCommandLineParser parser; parser.setApplicationDescription(this->description); @@ -56,7 +57,7 @@ int Diceware::execute(const QStringList& arguments) const QStringList args = parser.positionalArguments(); if (!args.isEmpty()) { - outputTextStream << parser.helpText().replace("keepassxc-cli", "keepassxc-cli diceware"); + errorTextStream << parser.helpText().replace("keepassxc-cli", "keepassxc-cli diceware"); return EXIT_FAILURE; } @@ -76,7 +77,7 @@ int Diceware::execute(const QStringList& arguments) } if (!dicewareGenerator.isValid()) { - outputTextStream << parser.helpText().replace("keepassxc-cli", "keepassxc-cli diceware"); + errorTextStream << parser.helpText().replace("keepassxc-cli", "keepassxc-cli diceware"); return EXIT_FAILURE; } diff --git a/src/cli/Edit.cpp b/src/cli/Edit.cpp index 056a0a595a..830a1bfc06 100644 --- a/src/cli/Edit.cpp +++ b/src/cli/Edit.cpp @@ -43,7 +43,7 @@ int Edit::execute(const QStringList& arguments) { QTextStream inputTextStream(stdin, QIODevice::ReadOnly); - QTextStream outputTextStream(stdout, QIODevice::WriteOnly); + QTextStream errorTextStream(stderr, QIODevice::WriteOnly); QCommandLineParser parser; parser.setApplicationDescription(this->description); @@ -91,7 +91,7 @@ int Edit::execute(const QStringList& arguments) const QStringList args = parser.positionalArguments(); if (args.size() != 2) { - outputTextStream << parser.helpText().replace("keepassxc-cli", "keepassxc-cli edit"); + errorTextStream << parser.helpText().replace("keepassxc-cli", "keepassxc-cli edit"); return EXIT_FAILURE; } @@ -137,8 +137,8 @@ int Edit::execute(const QStringList& arguments) } if (parser.isSet(prompt)) { - outputTextStream << "Enter new password for entry: "; - outputTextStream.flush(); + errorTextStream << "Enter new password for entry: "; + errorTextStream.flush(); QString password = Utils::getPassword(); entry->setPassword(password); } else if (parser.isSet(generate)) { @@ -164,6 +164,6 @@ int Edit::execute(const QStringList& arguments) return EXIT_FAILURE; } - outputTextStream << "Successfully edited entry " << entry->title() << "." << endl; + errorTextStream << "Successfully edited entry " << entry->title() << "." << endl; return EXIT_SUCCESS; } diff --git a/src/cli/Estimate.cpp b/src/cli/Estimate.cpp index 9a2ab0b0f7..b3276d1a95 100644 --- a/src/cli/Estimate.cpp +++ b/src/cli/Estimate.cpp @@ -141,7 +141,7 @@ static void estimate(const char* pwd, bool advanced) int Estimate::execute(const QStringList& arguments) { QTextStream inputTextStream(stdin, QIODevice::ReadOnly); - QTextStream outputTextStream(stdout, QIODevice::WriteOnly); + QTextStream errorTextStream(stderr, QIODevice::WriteOnly); QCommandLineParser parser; parser.setApplicationDescription(this->description); @@ -154,7 +154,7 @@ int Estimate::execute(const QStringList& arguments) const QStringList args = parser.positionalArguments(); if (args.size() > 1) { - outputTextStream << parser.helpText().replace("keepassxc-cli", "keepassxc-cli estimate"); + errorTextStream << parser.helpText().replace("keepassxc-cli", "keepassxc-cli estimate"); return EXIT_FAILURE; } diff --git a/src/cli/Extract.cpp b/src/cli/Extract.cpp index 089a784d2c..f419272808 100644 --- a/src/cli/Extract.cpp +++ b/src/cli/Extract.cpp @@ -43,8 +43,8 @@ Extract::~Extract() int Extract::execute(const QStringList& arguments) { - QTextStream out(stdout); QTextStream errorTextStream(stderr); + QTextStream outputTextStream(stdout); QCommandLineParser parser; parser.setApplicationDescription(this->description); @@ -58,12 +58,12 @@ int Extract::execute(const QStringList& arguments) const QStringList args = parser.positionalArguments(); if (args.size() != 1) { - out << parser.helpText().replace("keepassxc-cli", "keepassxc-cli extract"); + errorTextStream << parser.helpText().replace("keepassxc-cli", "keepassxc-cli extract"); return EXIT_FAILURE; } - out << QObject::tr("Insert password to unlock %1: ").arg(args.at(0)); - out.flush(); + errorTextStream << QObject::tr("Insert password to unlock %1: ").arg(args.at(0)); + errorTextStream.flush(); CompositeKey compositeKey; @@ -119,7 +119,7 @@ int Extract::execute(const QStringList& arguments) return EXIT_FAILURE; } - out << xmlData.constData() << "\n"; + outputTextStream << xmlData.constData() << "\n"; return EXIT_SUCCESS; } diff --git a/src/cli/Generate.cpp b/src/cli/Generate.cpp index 6a5be3f07d..2afebcaac3 100644 --- a/src/cli/Generate.cpp +++ b/src/cli/Generate.cpp @@ -39,6 +39,7 @@ int Generate::execute(const QStringList& arguments) { QTextStream inputTextStream(stdin, QIODevice::ReadOnly); QTextStream outputTextStream(stdout, QIODevice::WriteOnly); + QTextStream errorTextStream(stderr, QIODevice::WriteOnly); QCommandLineParser parser; parser.setApplicationDescription(this->description); @@ -83,7 +84,7 @@ int Generate::execute(const QStringList& arguments) const QStringList args = parser.positionalArguments(); if (!args.isEmpty()) { - outputTextStream << parser.helpText().replace("keepassxc-cli", "keepassxc-cli generate"); + errorTextStream << parser.helpText().replace("keepassxc-cli", "keepassxc-cli generate"); return EXIT_FAILURE; } @@ -128,7 +129,7 @@ int Generate::execute(const QStringList& arguments) passwordGenerator.setExcludedChars(parser.value(exclude)); if (!passwordGenerator.isValid()) { - outputTextStream << parser.helpText().replace("keepassxc-cli", "keepassxc-cli generate"); + errorTextStream << parser.helpText().replace("keepassxc-cli", "keepassxc-cli generate"); return EXIT_FAILURE; } diff --git a/src/cli/List.cpp b/src/cli/List.cpp index bdedaf210e..a7334b4f2e 100644 --- a/src/cli/List.cpp +++ b/src/cli/List.cpp @@ -39,7 +39,7 @@ List::~List() int List::execute(const QStringList& arguments) { - QTextStream out(stdout); + QTextStream errorTextStream(stderr); QCommandLineParser parser; parser.setApplicationDescription(this->description); @@ -54,7 +54,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; } diff --git a/src/cli/Locate.cpp b/src/cli/Locate.cpp index f803728855..9d139d5111 100644 --- a/src/cli/Locate.cpp +++ b/src/cli/Locate.cpp @@ -42,7 +42,7 @@ Locate::~Locate() int Locate::execute(const QStringList& arguments) { - QTextStream out(stdout); + QTextStream errorTextStream(stderr); QCommandLineParser parser; parser.setApplicationDescription(this->description); @@ -57,7 +57,7 @@ int Locate::execute(const QStringList& arguments) const QStringList args = parser.positionalArguments(); if (args.size() != 2) { - out << parser.helpText().replace("keepassxc-cli", "keepassxc-cli locate"); + errorTextStream << parser.helpText().replace("keepassxc-cli", "keepassxc-cli locate"); return EXIT_FAILURE; } @@ -72,15 +72,15 @@ int Locate::execute(const QStringList& arguments) int Locate::locateEntry(Database* database, QString searchTerm) { - QTextStream outputTextStream(stdout, QIODevice::WriteOnly); + QTextStream errorTextStream(stderr, QIODevice::WriteOnly); QStringList results = database->rootGroup()->locate(searchTerm); if (results.isEmpty()) { - outputTextStream << "No results for that search term" << endl; + errorTextStream << "No results for that search term" << endl; return EXIT_SUCCESS; } for (QString result : results) { - outputTextStream << result << endl; + errorTextStream << result << endl; } return EXIT_SUCCESS; } diff --git a/src/cli/Merge.cpp b/src/cli/Merge.cpp index 6b114bff3c..9b09ebc143 100644 --- a/src/cli/Merge.cpp +++ b/src/cli/Merge.cpp @@ -36,7 +36,7 @@ Merge::~Merge() int Merge::execute(const QStringList& arguments) { - QTextStream out(stdout); + QTextStream errorTextStream(stderr); QCommandLineParser parser; parser.setApplicationDescription(this->description); @@ -63,7 +63,7 @@ int Merge::execute(const QStringList& arguments) const QStringList args = parser.positionalArguments(); if (args.size() != 2) { - out << parser.helpText().replace("keepassxc-cli", "keepassxc-cli merge"); + errorTextStream << parser.helpText().replace("keepassxc-cli", "keepassxc-cli merge"); return EXIT_FAILURE; } @@ -90,6 +90,6 @@ int Merge::execute(const QStringList& arguments) return EXIT_FAILURE; } - out << "Successfully merged the database files.\n"; + errorTextStream << "Successfully merged the database files.\n"; return EXIT_SUCCESS; } diff --git a/src/cli/Remove.cpp b/src/cli/Remove.cpp index 64a5976e9a..8a1265c24f 100644 --- a/src/cli/Remove.cpp +++ b/src/cli/Remove.cpp @@ -44,7 +44,7 @@ Remove::~Remove() int Remove::execute(const QStringList& arguments) { - QTextStream outputTextStream(stdout, QIODevice::WriteOnly); + QTextStream errorTextStream(stderr, QIODevice::WriteOnly); QCommandLineParser parser; parser.setApplicationDescription(QCoreApplication::translate("main", "Remove an entry from the database.")); @@ -59,7 +59,7 @@ int Remove::execute(const QStringList& arguments) const QStringList args = parser.positionalArguments(); if (args.size() != 2) { - outputTextStream << parser.helpText().replace("keepassxc-cli", "keepassxc-cli rm"); + errorTextStream << parser.helpText().replace("keepassxc-cli", "keepassxc-cli rm"); return EXIT_FAILURE; } @@ -74,7 +74,7 @@ int Remove::execute(const QStringList& arguments) int Remove::removeEntry(Database* database, QString databasePath, QString entryPath) { - QTextStream outputTextStream(stdout, QIODevice::WriteOnly); + QTextStream errorTextStream(stderr, QIODevice::WriteOnly); Entry* entry = database->rootGroup()->findEntryByPath(entryPath); if (!entry) { qCritical("Entry %s not found.", qPrintable(entryPath)); @@ -97,9 +97,9 @@ int Remove::removeEntry(Database* database, QString databasePath, QString entryP } if (recycled) { - outputTextStream << "Successfully recycled entry " << entryTitle << "." << endl; + errorTextStream << "Successfully recycled entry " << entryTitle << "." << endl; } else { - outputTextStream << "Successfully deleted entry " << entryTitle << "." << endl; + errorTextStream << "Successfully deleted entry " << entryTitle << "." << endl; } return EXIT_SUCCESS; diff --git a/src/cli/Show.cpp b/src/cli/Show.cpp index be188c75c9..ee58ec5866 100644 --- a/src/cli/Show.cpp +++ b/src/cli/Show.cpp @@ -39,7 +39,7 @@ Show::~Show() int Show::execute(const QStringList& arguments) { - QTextStream out(stdout); + QTextStream errorTextStream(stderr); QCommandLineParser parser; parser.setApplicationDescription(this->description); @@ -63,7 +63,7 @@ int Show::execute(const QStringList& arguments) const QStringList args = parser.positionalArguments(); if (args.size() != 2) { - out << parser.helpText().replace("keepassxc-cli", "keepassxc-cli show"); + errorTextStream << parser.helpText().replace("keepassxc-cli", "keepassxc-cli show"); return EXIT_FAILURE; } diff --git a/src/cli/keepassxc-cli.cpp b/src/cli/keepassxc-cli.cpp index 1462f92b91..98f093e3ed 100644 --- a/src/cli/keepassxc-cli.cpp +++ b/src/cli/keepassxc-cli.cpp @@ -46,7 +46,7 @@ int main(int argc, char** argv) QCoreApplication app(argc, argv); app.setApplicationVersion(KEEPASSX_VERSION); - QTextStream out(stdout); + QTextStream outputTextStream(stdout); QStringList arguments; for (int i = 0; i < argc; ++i) { arguments << QString(argv[i]); @@ -72,7 +72,7 @@ int main(int argc, char** argv) if (parser.positionalArguments().size() < 1) { if (parser.isSet("version")) { // Switch to parser.showVersion() when available (QT 5.4). - out << KEEPASSX_VERSION << endl; + outputTextStream << KEEPASSX_VERSION << endl; return EXIT_SUCCESS; } parser.showHelp();