fix cli commands, translations and codestyle

This commit is contained in:
thez3ro 2018-02-06 01:17:36 +01:00
parent 6723f4215a
commit 1bfbb9242c
No known key found for this signature in database
GPG Key ID: F628F9E41DD7C073
30 changed files with 70 additions and 67 deletions

View File

@ -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);
}

View File

@ -25,7 +25,7 @@ class Add : public Command
public:
Add();
~Add();
int execute(QStringList arguments);
int execute(const QStringList& arguments);
};
#endif // KEEPASSXC_ADD_H

View File

@ -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);

View File

@ -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);
};

View File

@ -41,7 +41,7 @@ Command::~Command()
{
}
int Command::execute(QStringList)
int Command::execute(const QStringList&)
{
return EXIT_FAILURE;
}

View File

@ -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();

View File

@ -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;
}

View File

@ -25,7 +25,7 @@ class Diceware : public Command
public:
Diceware();
~Diceware();
int execute(QStringList arguments);
int execute(const QStringList& arguments);
};
#endif // KEEPASSXC_DICEWARE_H

View File

@ -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);
}

View File

@ -25,7 +25,7 @@ class Edit : public Command
public:
Edit();
~Edit();
int execute(QStringList arguments);
int execute(const QStringList& arguments);
};
#endif // KEEPASSXC_EDIT_H

View File

@ -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);

View File

@ -25,7 +25,7 @@ class Estimate : public Command
public:
Estimate();
~Estimate();
int execute(QStringList arguments);
int execute(const QStringList& arguments);
};
#endif // KEEPASSXC_ESTIMATE_H

View File

@ -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);

View File

@ -25,7 +25,7 @@ class Extract : public Command
public:
Extract();
~Extract();
int execute(QStringList arguments);
int execute(const QStringList& arguments);
};
#endif // KEEPASSXC_EXTRACT_H

View File

@ -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");

View File

@ -25,7 +25,7 @@ class Generate : public Command
public:
Generate();
~Generate();
int execute(QStringList arguments);
int execute(const QStringList& arguments);
};
#endif // KEEPASSXC_GENERATE_H

View File

@ -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);

View File

@ -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(""));
};

View File

@ -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);

View File

@ -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);
};

View File

@ -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);

View File

@ -25,7 +25,7 @@ class Merge : public Command
public:
Merge();
~Merge();
int execute(QStringList arguments);
int execute(const QStringList& arguments);
};
#endif // KEEPASSXC_MERGE_H

View File

@ -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);

View File

@ -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);
};

View File

@ -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);

View File

@ -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);
};

View File

@ -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 = "";

View File

@ -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

View File

@ -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] <database> <term>"
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]

View File

@ -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<PasswordGroup> passwordGroups() const;