CLI: Use stderr for password prompt

Fixes #3398.

Convert to QTextStream for all CLI IO and greatly improve CLI tests

* Completely overhaul CLI tests to be much more streamlined and easy to read. Removed unnecessary code blocks by using existing functions.

Co-authored-by: Emma Brooks <me@pluvano.com>
This commit is contained in:
Jonathan White 2020-05-11 07:31:29 -04:00
parent 612f8d2e5b
commit 485852c9db
30 changed files with 938 additions and 1407 deletions

View file

@ -37,15 +37,13 @@ Remove::Remove()
int Remove::executeWithDatabase(QSharedPointer<Database> database, QSharedPointer<QCommandLineParser> parser)
{
bool quiet = parser->isSet(Command::QuietOption);
auto& out = parser->isSet(Command::QuietOption) ? Utils::DEVNULL : Utils::STDOUT;
auto& err = Utils::STDERR;
auto& entryPath = parser->positionalArguments().at(1);
TextStream outputTextStream(quiet ? Utils::DEVNULL : Utils::STDOUT, QIODevice::WriteOnly);
TextStream errorTextStream(Utils::STDERR, QIODevice::WriteOnly);
QPointer<Entry> entry = database->rootGroup()->findEntryByPath(entryPath);
if (!entry) {
errorTextStream << QObject::tr("Entry %1 not found.").arg(entryPath) << endl;
err << QObject::tr("Entry %1 not found.").arg(entryPath) << endl;
return EXIT_FAILURE;
}
@ -61,14 +59,14 @@ int Remove::executeWithDatabase(QSharedPointer<Database> database, QSharedPointe
QString errorMessage;
if (!database->save(&errorMessage, true, false)) {
errorTextStream << QObject::tr("Unable to save database to file: %1").arg(errorMessage) << endl;
err << QObject::tr("Unable to save database to file: %1").arg(errorMessage) << endl;
return EXIT_FAILURE;
}
if (recycled) {
outputTextStream << QObject::tr("Successfully recycled entry %1.").arg(entryTitle) << endl;
out << QObject::tr("Successfully recycled entry %1.").arg(entryTitle) << endl;
} else {
outputTextStream << QObject::tr("Successfully deleted entry %1.").arg(entryTitle) << endl;
out << QObject::tr("Successfully deleted entry %1.").arg(entryTitle) << endl;
}
return EXIT_SUCCESS;