Adding --quiet option to the CLI. (#2507)

This commit is contained in:
louib 2018-11-28 11:24:12 -05:00 committed by Jonathan White
parent 4e49de1afb
commit fff0f11b33
21 changed files with 252 additions and 44 deletions

View file

@ -48,6 +48,7 @@ int Add::execute(const QStringList& arguments)
QCommandLineParser parser;
parser.setApplicationDescription(description);
parser.addPositionalArgument("database", QObject::tr("Path of the database."));
parser.addOption(Command::QuietOption);
QCommandLineOption keyFile(QStringList() << "k" << "key-file",
QObject::tr("Key file of the database."),
@ -89,7 +90,10 @@ int Add::execute(const QStringList& arguments)
const QString& databasePath = args.at(0);
const QString& entryPath = args.at(1);
auto db = Database::unlockFromStdin(databasePath, parser.value(keyFile), Utils::STDOUT, Utils::STDERR);
auto db = Database::unlockFromStdin(databasePath,
parser.value(keyFile),
parser.isSet(Command::QuietOption) ? Utils::DEVNULL : Utils::STDOUT,
Utils::STDERR);
if (!db) {
return EXIT_FAILURE;
}
@ -117,8 +121,10 @@ int Add::execute(const QStringList& arguments)
}
if (parser.isSet(prompt)) {
outputTextStream << QObject::tr("Enter password for new entry: ") << flush;
QString password = Utils::getPassword();
if (!parser.isSet(Command::QuietOption)) {
outputTextStream << QObject::tr("Enter password for new entry: ") << flush;
}
QString password = Utils::getPassword(parser.isSet(Command::QuietOption) ? Utils::DEVNULL : Utils::STDOUT);
entry->setPassword(password);
} else if (parser.isSet(generate)) {
PasswordGenerator passwordGenerator;
@ -141,6 +147,8 @@ int Add::execute(const QStringList& arguments)
return EXIT_FAILURE;
}
outputTextStream << QObject::tr("Successfully added entry %1.").arg(entry->title()) << endl;
if (!parser.isSet(Command::QuietOption)) {
outputTextStream << QObject::tr("Successfully added entry %1.").arg(entry->title()) << endl;
}
return EXIT_SUCCESS;
}