Global const for KeyFileOption (CLI) (#2505)

This commit is contained in:
louib 2018-11-28 16:15:15 -05:00 committed by Jonathan White
parent 1a2721529d
commit 49b82ea6a2
11 changed files with 34 additions and 55 deletions

View File

@ -49,11 +49,7 @@ int Add::execute(const QStringList& arguments)
parser.setApplicationDescription(description); parser.setApplicationDescription(description);
parser.addPositionalArgument("database", QObject::tr("Path of the database.")); parser.addPositionalArgument("database", QObject::tr("Path of the database."));
parser.addOption(Command::QuietOption); parser.addOption(Command::QuietOption);
parser.addOption(Command::KeyFileOption);
QCommandLineOption keyFile(QStringList() << "k" << "key-file",
QObject::tr("Key file of the database."),
QObject::tr("path"));
parser.addOption(keyFile);
QCommandLineOption username(QStringList() << "u" << "username", QCommandLineOption username(QStringList() << "u" << "username",
QObject::tr("Username for the entry."), QObject::tr("Username for the entry."),
@ -91,7 +87,7 @@ int Add::execute(const QStringList& arguments)
const QString& entryPath = args.at(1); const QString& entryPath = args.at(1);
auto db = Database::unlockFromStdin(databasePath, auto db = Database::unlockFromStdin(databasePath,
parser.value(keyFile), parser.value(Command::KeyFileOption),
parser.isSet(Command::QuietOption) ? Utils::DEVNULL : Utils::STDOUT, parser.isSet(Command::QuietOption) ? Utils::DEVNULL : Utils::STDOUT,
Utils::STDERR); Utils::STDERR);
if (!db) { if (!db) {

View File

@ -47,11 +47,9 @@ int Clip::execute(const QStringList& arguments)
QCommandLineParser parser; QCommandLineParser parser;
parser.setApplicationDescription(description); parser.setApplicationDescription(description);
parser.addPositionalArgument("database", QObject::tr("Path of the database.")); parser.addPositionalArgument("database", QObject::tr("Path of the database."));
QCommandLineOption keyFile(QStringList() << "k" << "key-file",
QObject::tr("Key file of the database."),
QObject::tr("path"));
parser.addOption(keyFile);
parser.addOption(Command::QuietOption); parser.addOption(Command::QuietOption);
parser.addOption(Command::KeyFileOption);
QCommandLineOption totp(QStringList() << "t" << "totp", QCommandLineOption totp(QStringList() << "t" << "totp",
QObject::tr("Copy the current TOTP to the clipboard.")); QObject::tr("Copy the current TOTP to the clipboard."));
parser.addOption(totp); parser.addOption(totp);
@ -68,7 +66,7 @@ int Clip::execute(const QStringList& arguments)
} }
auto db = Database::unlockFromStdin(args.at(0), auto db = Database::unlockFromStdin(args.at(0),
parser.value(keyFile), parser.value(Command::KeyFileOption),
parser.isSet(Command::QuietOption) ? Utils::DEVNULL : Utils::STDOUT, parser.isSet(Command::QuietOption) ? Utils::DEVNULL : Utils::STDOUT,
Utils::STDERR); Utils::STDERR);
if (!db) { if (!db) {

View File

@ -39,6 +39,13 @@ const QCommandLineOption Command::QuietOption =
QCommandLineOption(QStringList() << "q" QCommandLineOption(QStringList() << "q"
<< "quiet", << "quiet",
QObject::tr("Silence password prompt and other secondary outputs.")); QObject::tr("Silence password prompt and other secondary outputs."));
const QCommandLineOption Command::KeyFileOption =
QCommandLineOption(QStringList() << "k"
<< "key-file",
QObject::tr("Key file of the database."),
QObject::tr("path"));
QMap<QString, Command*> commands; QMap<QString, Command*> commands;
Command::~Command() Command::~Command()

View File

@ -39,6 +39,7 @@ public:
static Command* getCommand(const QString& commandName); static Command* getCommand(const QString& commandName);
static const QCommandLineOption QuietOption; static const QCommandLineOption QuietOption;
static const QCommandLineOption KeyFileOption;
}; };
#endif // KEEPASSXC_COMMAND_H #endif // KEEPASSXC_COMMAND_H

View File

@ -49,11 +49,7 @@ int Edit::execute(const QStringList& arguments)
parser.setApplicationDescription(description); parser.setApplicationDescription(description);
parser.addPositionalArgument("database", QObject::tr("Path of the database.")); parser.addPositionalArgument("database", QObject::tr("Path of the database."));
parser.addOption(Command::QuietOption); parser.addOption(Command::QuietOption);
parser.addOption(Command::KeyFileOption);
QCommandLineOption keyFile(QStringList() << "k" << "key-file",
QObject::tr("Key file of the database."),
QObject::tr("path"));
parser.addOption(keyFile);
QCommandLineOption username(QStringList() << "u" << "username", QCommandLineOption username(QStringList() << "u" << "username",
QObject::tr("Username for the entry."), QObject::tr("Username for the entry."),
@ -95,7 +91,7 @@ int Edit::execute(const QStringList& arguments)
const QString& entryPath = args.at(1); const QString& entryPath = args.at(1);
auto db = Database::unlockFromStdin(databasePath, auto db = Database::unlockFromStdin(databasePath,
parser.value(keyFile), parser.value(Command::KeyFileOption),
parser.isSet(Command::QuietOption) ? Utils::DEVNULL : Utils::STDOUT, parser.isSet(Command::QuietOption) ? Utils::DEVNULL : Utils::STDOUT,
Utils::STDERR); Utils::STDERR);
if (!db) { if (!db) {

View File

@ -50,10 +50,7 @@ int Extract::execute(const QStringList& arguments)
parser.setApplicationDescription(description); parser.setApplicationDescription(description);
parser.addPositionalArgument("database", QObject::tr("Path of the database to extract.")); parser.addPositionalArgument("database", QObject::tr("Path of the database to extract."));
parser.addOption(Command::QuietOption); parser.addOption(Command::QuietOption);
QCommandLineOption keyFile(QStringList() << "k" << "key-file", parser.addOption(Command::KeyFileOption);
QObject::tr("Key file of the database."),
QObject::tr("path"));
parser.addOption(keyFile);
parser.addHelpOption(); parser.addHelpOption();
parser.process(arguments); parser.process(arguments);
@ -74,7 +71,7 @@ int Extract::execute(const QStringList& arguments)
passwordKey->setPassword(line); passwordKey->setPassword(line);
compositeKey->addKey(passwordKey); compositeKey->addKey(passwordKey);
QString keyFilePath = parser.value(keyFile); QString keyFilePath = parser.value(Command::KeyFileOption);
if (!keyFilePath.isEmpty()) { if (!keyFilePath.isEmpty()) {
// LCOV_EXCL_START // LCOV_EXCL_START
auto fileKey = QSharedPointer<FileKey>::create(); auto fileKey = QSharedPointer<FileKey>::create();

View File

@ -47,10 +47,8 @@ int List::execute(const QStringList& arguments)
parser.addPositionalArgument("database", QObject::tr("Path of the database.")); parser.addPositionalArgument("database", QObject::tr("Path of the database."));
parser.addPositionalArgument("group", QObject::tr("Path of the group to list. Default is /"), "[group]"); parser.addPositionalArgument("group", QObject::tr("Path of the group to list. Default is /"), "[group]");
parser.addOption(Command::QuietOption); parser.addOption(Command::QuietOption);
QCommandLineOption keyFile(QStringList() << "k" << "key-file", parser.addOption(Command::KeyFileOption);
QObject::tr("Key file of the database."),
QObject::tr("path"));
parser.addOption(keyFile);
QCommandLineOption recursiveOption(QStringList() << "R" << "recursive", QCommandLineOption recursiveOption(QStringList() << "R" << "recursive",
QObject::tr("Recursively list the elements of the group.")); QObject::tr("Recursively list the elements of the group."));
parser.addOption(recursiveOption); parser.addOption(recursiveOption);
@ -66,7 +64,7 @@ int List::execute(const QStringList& arguments)
bool recursive = parser.isSet(recursiveOption); bool recursive = parser.isSet(recursiveOption);
auto db = Database::unlockFromStdin(args.at(0), auto db = Database::unlockFromStdin(args.at(0),
parser.value(keyFile), parser.value(Command::KeyFileOption),
parser.isSet(Command::QuietOption) ? Utils::DEVNULL : Utils::STDOUT, parser.isSet(Command::QuietOption) ? Utils::DEVNULL : Utils::STDOUT,
Utils::STDERR); Utils::STDERR);
if (!db) { if (!db) {

View File

@ -49,10 +49,7 @@ int Locate::execute(const QStringList& arguments)
parser.addPositionalArgument("database", QObject::tr("Path of the database.")); parser.addPositionalArgument("database", QObject::tr("Path of the database."));
parser.addPositionalArgument("term", QObject::tr("Search term.")); parser.addPositionalArgument("term", QObject::tr("Search term."));
parser.addOption(Command::QuietOption); parser.addOption(Command::QuietOption);
QCommandLineOption keyFile(QStringList() << "k" << "key-file", parser.addOption(Command::KeyFileOption);
QObject::tr("Key file of the database."),
QObject::tr("path"));
parser.addOption(keyFile);
parser.addHelpOption(); parser.addHelpOption();
parser.process(arguments); parser.process(arguments);
@ -63,7 +60,7 @@ int Locate::execute(const QStringList& arguments)
} }
auto db = Database::unlockFromStdin(args.at(0), auto db = Database::unlockFromStdin(args.at(0),
parser.value(keyFile), parser.value(Command::KeyFileOption),
parser.isSet(Command::QuietOption) ? Utils::DEVNULL : Utils::STDOUT, parser.isSet(Command::QuietOption) ? Utils::DEVNULL : Utils::STDOUT,
Utils::STDERR); Utils::STDERR);
if (!db) { if (!db) {

View File

@ -50,14 +50,12 @@ int Merge::execute(const QStringList& arguments)
QCommandLineOption samePasswordOption(QStringList() << "s" << "same-credentials", QCommandLineOption samePasswordOption(QStringList() << "s" << "same-credentials",
QObject::tr("Use the same credentials for both database files.")); QObject::tr("Use the same credentials for both database files."));
parser.addOption(samePasswordOption); parser.addOption(samePasswordOption);
QCommandLineOption keyFile(QStringList() << "k" << "key-file", parser.addOption(Command::KeyFileOption);
QObject::tr("Key file of the database."),
QObject::tr("path")); QCommandLineOption keyFileFromOption(QStringList() << "f" << "key-file-from",
parser.addOption(keyFile); QObject::tr("Key file of the database to merge from."),
QCommandLineOption keyFileFrom(QStringList() << "f" << "key-file-from", QObject::tr("path"));
QObject::tr("Key file of the database to merge from."), parser.addOption(keyFileFromOption);
QObject::tr("path"));
parser.addOption(keyFileFrom);
parser.addHelpOption(); parser.addHelpOption();
parser.process(arguments); parser.process(arguments);
@ -69,7 +67,7 @@ int Merge::execute(const QStringList& arguments)
} }
auto db1 = Database::unlockFromStdin(args.at(0), auto db1 = Database::unlockFromStdin(args.at(0),
parser.value(keyFile), parser.value(Command::KeyFileOption),
parser.isSet(Command::QuietOption) ? Utils::DEVNULL : Utils::STDOUT, parser.isSet(Command::QuietOption) ? Utils::DEVNULL : Utils::STDOUT,
Utils::STDERR); Utils::STDERR);
if (!db1) { if (!db1) {
@ -78,10 +76,7 @@ int Merge::execute(const QStringList& arguments)
QSharedPointer<Database> db2; QSharedPointer<Database> db2;
if (!parser.isSet("same-credentials")) { if (!parser.isSet("same-credentials")) {
db2 = Database::unlockFromStdin(args.at(1), db2 = Database::unlockFromStdin(args.at(1), parser.value(keyFileFromOption), Utils::STDOUT, Utils::STDERR);
parser.value(keyFileFrom),
parser.isSet(Command::QuietOption) ? Utils::DEVNULL : Utils::STDOUT,
Utils::STDERR);
} else { } else {
db2 = QSharedPointer<Database>::create(); db2 = QSharedPointer<Database>::create();
QString errorMessage; QString errorMessage;

View File

@ -50,10 +50,7 @@ int Remove::execute(const QStringList& arguments)
parser.setApplicationDescription(QCoreApplication::tr("main", "Remove an entry from the database.")); parser.setApplicationDescription(QCoreApplication::tr("main", "Remove an entry from the database."));
parser.addPositionalArgument("database", QCoreApplication::tr("main", "Path of the database.")); parser.addPositionalArgument("database", QCoreApplication::tr("main", "Path of the database."));
parser.addOption(Command::QuietOption); parser.addOption(Command::QuietOption);
QCommandLineOption keyFile(QStringList() << "k" << "key-file", parser.addOption(Command::KeyFileOption);
QObject::tr("Key file of the database."),
QObject::tr("path"));
parser.addOption(keyFile);
parser.addPositionalArgument("entry", QCoreApplication::tr("main", "Path of the entry to remove.")); parser.addPositionalArgument("entry", QCoreApplication::tr("main", "Path of the entry to remove."));
parser.addHelpOption(); parser.addHelpOption();
parser.process(arguments); parser.process(arguments);
@ -65,7 +62,7 @@ int Remove::execute(const QStringList& arguments)
} }
auto db = Database::unlockFromStdin(args.at(0), auto db = Database::unlockFromStdin(args.at(0),
parser.value(keyFile), parser.value(Command::KeyFileOption),
parser.isSet(Command::QuietOption) ? Utils::DEVNULL : Utils::STDOUT, parser.isSet(Command::QuietOption) ? Utils::DEVNULL : Utils::STDOUT,
Utils::STDERR); Utils::STDERR);
if (!db) { if (!db) {

View File

@ -46,11 +46,8 @@ int Show::execute(const QStringList& arguments)
QCommandLineParser parser; QCommandLineParser parser;
parser.setApplicationDescription(description); parser.setApplicationDescription(description);
parser.addPositionalArgument("database", QObject::tr("Path of the database.")); parser.addPositionalArgument("database", QObject::tr("Path of the database."));
QCommandLineOption keyFile(QStringList() << "k" << "key-file",
QObject::tr("Key file of the database."),
QObject::tr("path"));
parser.addOption(keyFile);
parser.addOption(Command::QuietOption); parser.addOption(Command::QuietOption);
parser.addOption(Command::KeyFileOption);
QCommandLineOption totp(QStringList() << "t" << "totp", QCommandLineOption totp(QStringList() << "t" << "totp",
QObject::tr("Show the entry's current TOTP.")); QObject::tr("Show the entry's current TOTP."));
parser.addOption(totp); parser.addOption(totp);
@ -73,7 +70,7 @@ int Show::execute(const QStringList& arguments)
} }
auto db = Database::unlockFromStdin(args.at(0), auto db = Database::unlockFromStdin(args.at(0),
parser.value(keyFile), parser.value(Command::KeyFileOption),
parser.isSet(Command::QuietOption) ? Utils::DEVNULL : Utils::STDOUT, parser.isSet(Command::QuietOption) ? Utils::DEVNULL : Utils::STDOUT,
Utils::STDERR); Utils::STDERR);
if (!db) { if (!db) {