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

@ -49,6 +49,7 @@ int Remove::execute(const QStringList& arguments)
QCommandLineParser parser;
parser.setApplicationDescription(QCoreApplication::tr("main", "Remove an entry from the database."));
parser.addPositionalArgument("database", QCoreApplication::tr("main", "Path of the database."));
parser.addOption(Command::QuietOption);
QCommandLineOption keyFile(QStringList() << "k" << "key-file",
QObject::tr("Key file of the database."),
QObject::tr("path"));
@ -63,17 +64,20 @@ int Remove::execute(const QStringList& arguments)
return EXIT_FAILURE;
}
auto db = Database::unlockFromStdin(args.at(0), parser.value(keyFile), Utils::STDOUT, Utils::STDERR);
auto db = Database::unlockFromStdin(args.at(0),
parser.value(keyFile),
parser.isSet(Command::QuietOption) ? Utils::DEVNULL : Utils::STDOUT,
Utils::STDERR);
if (!db) {
return EXIT_FAILURE;
}
return removeEntry(db.data(), args.at(0), args.at(1));
return removeEntry(db.data(), args.at(0), args.at(1), parser.isSet(Command::QuietOption));
}
int Remove::removeEntry(Database* database, const QString& databasePath, const QString& entryPath)
int Remove::removeEntry(Database* database, const QString& databasePath, const QString& entryPath, bool quiet)
{
TextStream out(Utils::STDOUT, QIODevice::WriteOnly);
TextStream out(quiet ? Utils::DEVNULL : Utils::STDOUT, QIODevice::WriteOnly);
TextStream err(Utils::STDERR, QIODevice::WriteOnly);
QPointer<Entry> entry = database->rootGroup()->findEntryByPath(entryPath);