From 1bfbb9242c8747bb192ce05d94e4c4a28219d9b0 Mon Sep 17 00:00:00 2001 From: thez3ro Date: Tue, 6 Feb 2018 01:17:36 +0100 Subject: [PATCH] fix cli commands, translations and codestyle --- src/cli/Add.cpp | 7 ++++--- src/cli/Add.h | 2 +- src/cli/Clip.cpp | 6 +++--- src/cli/Clip.h | 2 +- src/cli/Command.cpp | 2 +- src/cli/Command.h | 2 +- src/cli/Diceware.cpp | 10 +++++----- src/cli/Diceware.h | 2 +- src/cli/Edit.cpp | 7 ++++--- src/cli/Edit.h | 2 +- src/cli/Estimate.cpp | 6 +++--- src/cli/Estimate.h | 2 +- src/cli/Extract.cpp | 6 +++--- src/cli/Extract.h | 2 +- src/cli/Generate.cpp | 15 ++++++++------- src/cli/Generate.h | 2 +- src/cli/List.cpp | 6 +++--- src/cli/List.h | 2 +- src/cli/Locate.cpp | 6 +++--- src/cli/Locate.h | 2 +- src/cli/Merge.cpp | 6 +++--- src/cli/Merge.h | 2 +- src/cli/Remove.cpp | 6 +++--- src/cli/Remove.h | 2 +- src/cli/Show.cpp | 6 +++--- src/cli/Show.h | 2 +- src/cli/Utils.cpp | 2 +- src/cli/Utils.h | 2 +- src/cli/keepassxc-cli.1 | 4 ++-- src/core/PasswordGenerator.h | 14 +++++++------- 30 files changed, 70 insertions(+), 67 deletions(-) diff --git a/src/cli/Add.cpp b/src/cli/Add.cpp index 6954532cd..5c97299b8 100644 --- a/src/cli/Add.cpp +++ b/src/cli/Add.cpp @@ -31,15 +31,15 @@ Add::Add() { - this->name = QString("add"); - this->description = QObject::tr("Add a new entry to a database."); + name = QString("add"); + description = QObject::tr("Add a new entry to a database."); } Add::~Add() { } -int Add::execute(QStringList arguments) +int Add::execute(const QStringList& arguments) { QTextStream inputTextStream(stdin, QIODevice::ReadOnly); @@ -134,6 +134,7 @@ int Add::execute(QStringList arguments) } passwordGenerator.setCharClasses(PasswordGenerator::DefaultCharset); + passwordGenerator.setFlags(PasswordGenerator::DefaultFlags); QString password = passwordGenerator.generatePassword(); entry->setPassword(password); } diff --git a/src/cli/Add.h b/src/cli/Add.h index 14356c418..5769249c9 100644 --- a/src/cli/Add.h +++ b/src/cli/Add.h @@ -25,7 +25,7 @@ class Add : public Command public: Add(); ~Add(); - int execute(QStringList arguments); + int execute(const QStringList& arguments); }; #endif // KEEPASSXC_ADD_H diff --git a/src/cli/Clip.cpp b/src/cli/Clip.cpp index 6b458a673..886f8ecc7 100644 --- a/src/cli/Clip.cpp +++ b/src/cli/Clip.cpp @@ -32,15 +32,15 @@ Clip::Clip() { - this->name = QString("clip"); - this->description = QObject::tr("Copy an entry's password to the clipboard."); + name = QString("clip"); + description = QObject::tr("Copy an entry's password to the clipboard."); } Clip::~Clip() { } -int Clip::execute(QStringList arguments) +int Clip::execute(const QStringList& arguments) { QTextStream out(stdout); diff --git a/src/cli/Clip.h b/src/cli/Clip.h index a9e24faee..e94231236 100644 --- a/src/cli/Clip.h +++ b/src/cli/Clip.h @@ -25,7 +25,7 @@ class Clip : public Command public: Clip(); ~Clip(); - int execute(QStringList arguments); + int execute(const QStringList& arguments); int clipEntry(Database* database, QString entryPath, QString timeout); }; diff --git a/src/cli/Command.cpp b/src/cli/Command.cpp index f0441fd7f..ef6948888 100644 --- a/src/cli/Command.cpp +++ b/src/cli/Command.cpp @@ -41,7 +41,7 @@ Command::~Command() { } -int Command::execute(QStringList) +int Command::execute(const QStringList&) { return EXIT_FAILURE; } diff --git a/src/cli/Command.h b/src/cli/Command.h index b751c4a8e..2ebdd77b9 100644 --- a/src/cli/Command.h +++ b/src/cli/Command.h @@ -29,7 +29,7 @@ class Command { public: virtual ~Command(); - virtual int execute(QStringList arguments); + virtual int execute(const QStringList& arguments); QString name; QString description; QString getDescriptionLine(); diff --git a/src/cli/Diceware.cpp b/src/cli/Diceware.cpp index 080a21c1f..c71b57d7e 100644 --- a/src/cli/Diceware.cpp +++ b/src/cli/Diceware.cpp @@ -27,15 +27,15 @@ Diceware::Diceware() { - this->name = QString("diceware"); - this->description = QObject::tr("Generate a new random password."); + name = QString("diceware"); + description = QObject::tr("Generate a new random diceware passphrase."); } Diceware::~Diceware() { } -int Diceware::execute(QStringList arguments) +int Diceware::execute(const QStringList& arguments) { QTextStream inputTextStream(stdin, QIODevice::ReadOnly); QTextStream outputTextStream(stdout, QIODevice::WriteOnly); @@ -48,13 +48,13 @@ int Diceware::execute(QStringList arguments) parser.addOption(words); QCommandLineOption wordlistFile(QStringList() << "w" << "word-list", - QObject::tr("Wordlist fot the diceware generator.\n[Default: EFF English]"), + QObject::tr("Wordlist for the diceware generator.\n[Default: EFF English]"), QObject::tr("path")); parser.addOption(wordlistFile); parser.process(arguments); const QStringList args = parser.positionalArguments(); - if (args.size() != 0) { + if (!args.isEmpty()) { outputTextStream << parser.helpText().replace("keepassxc-cli", "keepassxc-cli diceware"); return EXIT_FAILURE; } diff --git a/src/cli/Diceware.h b/src/cli/Diceware.h index b6d71b6c6..61fe724ca 100644 --- a/src/cli/Diceware.h +++ b/src/cli/Diceware.h @@ -25,7 +25,7 @@ class Diceware : public Command public: Diceware(); ~Diceware(); - int execute(QStringList arguments); + int execute(const QStringList& arguments); }; #endif // KEEPASSXC_DICEWARE_H diff --git a/src/cli/Edit.cpp b/src/cli/Edit.cpp index 675ec7def..967ddd8ed 100644 --- a/src/cli/Edit.cpp +++ b/src/cli/Edit.cpp @@ -31,15 +31,15 @@ Edit::Edit() { - this->name = QString("edit"); - this->description = QObject::tr("Edit an entry."); + name = QString("edit"); + description = QObject::tr("Edit an entry."); } Edit::~Edit() { } -int Edit::execute(QStringList arguments) +int Edit::execute(const QStringList& arguments) { QTextStream inputTextStream(stdin, QIODevice::ReadOnly); @@ -150,6 +150,7 @@ int Edit::execute(QStringList arguments) } passwordGenerator.setCharClasses(PasswordGenerator::DefaultCharset); + passwordGenerator.setFlags(PasswordGenerator::DefaultFlags); QString password = passwordGenerator.generatePassword(); entry->setPassword(password); } diff --git a/src/cli/Edit.h b/src/cli/Edit.h index e52069ff0..2c413bea0 100644 --- a/src/cli/Edit.h +++ b/src/cli/Edit.h @@ -25,7 +25,7 @@ class Edit : public Command public: Edit(); ~Edit(); - int execute(QStringList arguments); + int execute(const QStringList& arguments); }; #endif // KEEPASSXC_EDIT_H diff --git a/src/cli/Estimate.cpp b/src/cli/Estimate.cpp index 80226a27e..9a2ab0b0f 100644 --- a/src/cli/Estimate.cpp +++ b/src/cli/Estimate.cpp @@ -34,8 +34,8 @@ Estimate::Estimate() { - this->name = QString("estimate"); - this->description = QObject::tr("Estimate the entropy of a password."); + name = QString("estimate"); + description = QObject::tr("Estimate the entropy of a password."); } Estimate::~Estimate() @@ -138,7 +138,7 @@ static void estimate(const char* pwd, bool advanced) } } -int Estimate::execute(QStringList arguments) +int Estimate::execute(const QStringList& arguments) { QTextStream inputTextStream(stdin, QIODevice::ReadOnly); QTextStream outputTextStream(stdout, QIODevice::WriteOnly); diff --git a/src/cli/Estimate.h b/src/cli/Estimate.h index 2cbe49104..15f922752 100644 --- a/src/cli/Estimate.h +++ b/src/cli/Estimate.h @@ -25,7 +25,7 @@ class Estimate : public Command public: Estimate(); ~Estimate(); - int execute(QStringList arguments); + int execute(const QStringList& arguments); }; #endif // KEEPASSXC_ESTIMATE_H diff --git a/src/cli/Extract.cpp b/src/cli/Extract.cpp index 477f2b0e2..b48d5a6aa 100644 --- a/src/cli/Extract.cpp +++ b/src/cli/Extract.cpp @@ -33,15 +33,15 @@ Extract::Extract() { - this->name = QString("extract"); - this->description = QObject::tr("Extract and print the content of a database."); + name = QString("extract"); + description = QObject::tr("Extract and print the content of a database."); } Extract::~Extract() { } -int Extract::execute(QStringList arguments) +int Extract::execute(const QStringList& arguments) { QTextStream out(stdout); QTextStream errorTextStream(stderr); diff --git a/src/cli/Extract.h b/src/cli/Extract.h index bef6a7821..2939afddb 100644 --- a/src/cli/Extract.h +++ b/src/cli/Extract.h @@ -25,7 +25,7 @@ class Extract : public Command public: Extract(); ~Extract(); - int execute(QStringList arguments); + int execute(const QStringList& arguments); }; #endif // KEEPASSXC_EXTRACT_H diff --git a/src/cli/Generate.cpp b/src/cli/Generate.cpp index 3588cb421..eb8fea5e8 100644 --- a/src/cli/Generate.cpp +++ b/src/cli/Generate.cpp @@ -27,15 +27,15 @@ Generate::Generate() { - this->name = QString("generate"); - this->description = QObject::tr("Generate a new random password."); + name = QString("generate"); + description = QObject::tr("Generate a new random password."); } Generate::~Generate() { } -int Generate::execute(QStringList arguments) +int Generate::execute(const QStringList& arguments) { QTextStream inputTextStream(stdin, QIODevice::ReadOnly); QTextStream outputTextStream(stdout, QIODevice::WriteOnly); @@ -47,10 +47,10 @@ int Generate::execute(QStringList arguments) QObject::tr("length")); parser.addOption(len); QCommandLineOption lower(QStringList() << "l", - QObject::tr("Use lowercase in the generated password.")); + QObject::tr("Use lowercase characters in the generated password.")); parser.addOption(lower); QCommandLineOption upper(QStringList() << "u", - QObject::tr("Use uppercase in the generated password.")); + QObject::tr("Use uppercase characters in the generated password.")); parser.addOption(upper); QCommandLineOption numeric(QStringList() << "n", QObject::tr("Use numbers in the generated password.")); @@ -59,12 +59,12 @@ int Generate::execute(QStringList arguments) QObject::tr("Use special characters in the generated password.")); parser.addOption(special); QCommandLineOption extended(QStringList() << "e", - QObject::tr("Use extended ascii in the generated password.")); + QObject::tr("Use extended ASCII in the generated password.")); parser.addOption(extended); parser.process(arguments); const QStringList args = parser.positionalArguments(); - if (args.size() != 0) { + if (!args.isEmpty()) { outputTextStream << parser.helpText().replace("keepassxc-cli", "keepassxc-cli generate"); return EXIT_FAILURE; } @@ -97,6 +97,7 @@ int Generate::execute(QStringList arguments) } passwordGenerator.setCharClasses(classes); + passwordGenerator.setFlags(PasswordGenerator::DefaultFlags); if (!passwordGenerator.isValid()) { outputTextStream << parser.helpText().replace("keepassxc-cli", "keepassxc-cli generate"); diff --git a/src/cli/Generate.h b/src/cli/Generate.h index de6a8ea11..607fc105c 100644 --- a/src/cli/Generate.h +++ b/src/cli/Generate.h @@ -25,7 +25,7 @@ class Generate : public Command public: Generate(); ~Generate(); - int execute(QStringList arguments); + int execute(const QStringList& arguments); }; #endif // KEEPASSXC_GENERATE_H diff --git a/src/cli/List.cpp b/src/cli/List.cpp index 73830cab8..bdedaf210 100644 --- a/src/cli/List.cpp +++ b/src/cli/List.cpp @@ -29,15 +29,15 @@ List::List() { - this->name = QString("ls"); - this->description = QObject::tr("List database entries."); + name = QString("ls"); + description = QObject::tr("List database entries."); } List::~List() { } -int List::execute(QStringList arguments) +int List::execute(const QStringList& arguments) { QTextStream out(stdout); diff --git a/src/cli/List.h b/src/cli/List.h index d12105f3c..98b8b5a45 100644 --- a/src/cli/List.h +++ b/src/cli/List.h @@ -25,7 +25,7 @@ class List : public Command public: List(); ~List(); - int execute(QStringList arguments); + int execute(const QStringList& arguments); int listGroup(Database* database, QString groupPath = QString("")); }; diff --git a/src/cli/Locate.cpp b/src/cli/Locate.cpp index 83a3c5ce0..f80372885 100644 --- a/src/cli/Locate.cpp +++ b/src/cli/Locate.cpp @@ -31,15 +31,15 @@ Locate::Locate() { - this->name = QString("locate"); - this->description = QObject::tr("Find entries quickly."); + name = QString("locate"); + description = QObject::tr("Find entries quickly."); } Locate::~Locate() { } -int Locate::execute(QStringList arguments) +int Locate::execute(const QStringList& arguments) { QTextStream out(stdout); diff --git a/src/cli/Locate.h b/src/cli/Locate.h index c919b0cb3..3677a034d 100644 --- a/src/cli/Locate.h +++ b/src/cli/Locate.h @@ -25,7 +25,7 @@ class Locate : public Command public: Locate(); ~Locate(); - int execute(QStringList arguments); + int execute(const QStringList& arguments); int locateEntry(Database* database, QString searchTerm); }; diff --git a/src/cli/Merge.cpp b/src/cli/Merge.cpp index 5df6b0188..6b114bff3 100644 --- a/src/cli/Merge.cpp +++ b/src/cli/Merge.cpp @@ -26,15 +26,15 @@ Merge::Merge() { - this->name = QString("merge"); - this->description = QObject::tr("Merge two databases."); + name = QString("merge"); + description = QObject::tr("Merge two databases."); } Merge::~Merge() { } -int Merge::execute(QStringList arguments) +int Merge::execute(const QStringList& arguments) { QTextStream out(stdout); diff --git a/src/cli/Merge.h b/src/cli/Merge.h index 4f0b42836..496c66b86 100644 --- a/src/cli/Merge.h +++ b/src/cli/Merge.h @@ -25,7 +25,7 @@ class Merge : public Command public: Merge(); ~Merge(); - int execute(QStringList arguments); + int execute(const QStringList& arguments); }; #endif // KEEPASSXC_MERGE_H diff --git a/src/cli/Remove.cpp b/src/cli/Remove.cpp index 6abb68f1c..64a5976e9 100644 --- a/src/cli/Remove.cpp +++ b/src/cli/Remove.cpp @@ -34,15 +34,15 @@ Remove::Remove() { - this->name = QString("rm"); - this->description = QString("Remove an entry from the database."); + name = QString("rm"); + description = QString("Remove an entry from the database."); } Remove::~Remove() { } -int Remove::execute(QStringList arguments) +int Remove::execute(const QStringList& arguments) { QTextStream outputTextStream(stdout, QIODevice::WriteOnly); diff --git a/src/cli/Remove.h b/src/cli/Remove.h index 2440c201c..5465530ed 100644 --- a/src/cli/Remove.h +++ b/src/cli/Remove.h @@ -27,7 +27,7 @@ class Remove : public Command public: Remove(); ~Remove(); - int execute(QStringList arguments); + int execute(const QStringList& arguments); int removeEntry(Database* database, QString databasePath, QString entryPath); }; diff --git a/src/cli/Show.cpp b/src/cli/Show.cpp index 66225c56a..54561b1f7 100644 --- a/src/cli/Show.cpp +++ b/src/cli/Show.cpp @@ -29,15 +29,15 @@ Show::Show() { - this->name = QString("show"); - this->description = QObject::tr("Show an entry's information."); + name = QString("show"); + description = QObject::tr("Show an entry's information."); } Show::~Show() { } -int Show::execute(QStringList arguments) +int Show::execute(const QStringList& arguments) { QTextStream out(stdout); diff --git a/src/cli/Show.h b/src/cli/Show.h index f2caefdbf..18b6d7049 100644 --- a/src/cli/Show.h +++ b/src/cli/Show.h @@ -25,7 +25,7 @@ class Show : public Command public: Show(); ~Show(); - int execute(QStringList arguments); + int execute(const QStringList& arguments); int showEntry(Database* database, QStringList attributes, QString entryPath); }; diff --git a/src/cli/Utils.cpp b/src/cli/Utils.cpp index f42095cbb..35e7cce38 100644 --- a/src/cli/Utils.cpp +++ b/src/cli/Utils.cpp @@ -76,7 +76,7 @@ QString Utils::getPassword() * A valid and running event loop is needed to use the global QClipboard, * so we need to use this from the CLI. */ -int Utils::clipText(QString text) +int Utils::clipText(const QString& text) { QString programName = ""; diff --git a/src/cli/Utils.h b/src/cli/Utils.h index 0c6b749a3..1f8051183 100644 --- a/src/cli/Utils.h +++ b/src/cli/Utils.h @@ -25,7 +25,7 @@ class Utils public: static void setStdinEcho(bool enable); static QString getPassword(); - static int clipText(QString text); + static int clipText(const QString& text); }; #endif // KEEPASSXC_UTILS_H diff --git a/src/cli/keepassxc-cli.1 b/src/cli/keepassxc-cli.1 index ebd3ea3da..cc1e7b8d7 100644 --- a/src/cli/keepassxc-cli.1 +++ b/src/cli/keepassxc-cli.1 @@ -32,7 +32,7 @@ Estimates the entropy of a password. The password to estimate can be provided as Extracts and prints the contents of a database to standard output in XML format. .IP "generate [options]" -Generate a random password +Generate a random password. .IP "locate [options] " Locates all the entries that match a specific search term in a database. @@ -139,7 +139,7 @@ Use numbers characters for the generated password. [Default: Enabled] Use special characters for the generated password. [Default: Disabled] .IP "-e" -Use extended ascii characters for the generated password. [Default: Disabled] +Use extended ASCII characters for the generated password. [Default: Disabled] diff --git a/src/core/PasswordGenerator.h b/src/core/PasswordGenerator.h index d1b2a0b39..15a0dcefe 100644 --- a/src/core/PasswordGenerator.h +++ b/src/core/PasswordGenerator.h @@ -61,13 +61,13 @@ public: int getbits() const; static const int DefaultLength = 16; - static const bool DefaultLower = (DefaultCharset & LowerLetters) != 0; - static const bool DefaultUpper = (DefaultCharset & UpperLetters) != 0; - static const bool DefaultNumbers = (DefaultCharset & Numbers) != 0; - static const bool DefaultSpecial = (DefaultCharset & SpecialCharacters) != 0; - static const bool DefaultEASCII = (DefaultCharset & EASCII) != 0; - static const bool DefaultLookAlike = (DefaultFlags & ExcludeLookAlike) != 0; - static const bool DefaultFromEveryGroup = (DefaultFlags & CharFromEveryGroup) != 0; + static constexpr bool DefaultLower = (DefaultCharset & LowerLetters) != 0; + static constexpr bool DefaultUpper = (DefaultCharset & UpperLetters) != 0; + static constexpr bool DefaultNumbers = (DefaultCharset & Numbers) != 0; + static constexpr bool DefaultSpecial = (DefaultCharset & SpecialCharacters) != 0; + static constexpr bool DefaultEASCII = (DefaultCharset & EASCII) != 0; + static constexpr bool DefaultLookAlike = (DefaultFlags & ExcludeLookAlike) != 0; + static constexpr bool DefaultFromEveryGroup = (DefaultFlags & CharFromEveryGroup) != 0; private: QVector passwordGroups() const;