From 4782b20d6144769e35d5bdec9e23b9677e844344 Mon Sep 17 00:00:00 2001 From: thez3ro Date: Wed, 31 Jan 2018 00:50:02 +0100 Subject: [PATCH] renamed passgen to generate and use diceware default wordcount --- src/cli/CMakeLists.txt | 4 ++-- src/cli/Command.cpp | 4 ++-- src/cli/Diceware.cpp | 15 +++++++++++---- src/cli/{PassGen.cpp => Generate.cpp} | 14 +++++++------- src/cli/{PassGen.h => Generate.h} | 12 ++++++------ 5 files changed, 28 insertions(+), 21 deletions(-) rename src/cli/{PassGen.cpp => Generate.cpp} (94%) rename src/cli/{PassGen.h => Generate.h} (83%) diff --git a/src/cli/CMakeLists.txt b/src/cli/CMakeLists.txt index 92277811b..a5126f999 100644 --- a/src/cli/CMakeLists.txt +++ b/src/cli/CMakeLists.txt @@ -28,14 +28,14 @@ set(cli_SOURCES Estimate.h Extract.cpp Extract.h + Generate.cpp + Generate.h List.cpp List.h Locate.cpp Locate.h Merge.cpp Merge.h - PassGen.cpp - PassGen.h Remove.cpp Remove.h Show.cpp diff --git a/src/cli/Command.cpp b/src/cli/Command.cpp index a9a53449e..f0441fd7f 100644 --- a/src/cli/Command.cpp +++ b/src/cli/Command.cpp @@ -28,10 +28,10 @@ #include "Edit.h" #include "Estimate.h" #include "Extract.h" +#include "Generate.h" #include "List.h" #include "Locate.h" #include "Merge.h" -#include "PassGen.h" #include "Remove.h" #include "Show.h" @@ -67,10 +67,10 @@ void populateCommands() commands.insert(QString("edit"), new Edit()); commands.insert(QString("estimate"), new Estimate()); commands.insert(QString("extract"), new Extract()); + commands.insert(QString("generate"), new Generate()); commands.insert(QString("locate"), new Locate()); commands.insert(QString("ls"), new List()); commands.insert(QString("merge"), new Merge()); - commands.insert(QString("passgen"), new PassGen()); commands.insert(QString("rm"), new Remove()); commands.insert(QString("show"), new Show()); } diff --git a/src/cli/Diceware.cpp b/src/cli/Diceware.cpp index 361be1625..080a21c1f 100644 --- a/src/cli/Diceware.cpp +++ b/src/cli/Diceware.cpp @@ -42,24 +42,31 @@ int Diceware::execute(QStringList arguments) QCommandLineParser parser; parser.setApplicationDescription(this->description); + QCommandLineOption words(QStringList() << "W" << "words", + QObject::tr("Word count for the diceware passphrase."), + QObject::tr("count")); + parser.addOption(words); QCommandLineOption wordlistFile(QStringList() << "w" << "word-list", QObject::tr("Wordlist fot the diceware generator.\n[Default: EFF English]"), QObject::tr("path")); parser.addOption(wordlistFile); - parser.addPositionalArgument("words", QObject::tr("Word count for the diceware generator.")); parser.process(arguments); const QStringList args = parser.positionalArguments(); - if (args.size() != 1) { + if (args.size() != 0) { outputTextStream << parser.helpText().replace("keepassxc-cli", "keepassxc-cli diceware"); return EXIT_FAILURE; } PassphraseGenerator dicewareGenerator; - int words = args.at(0).toInt(); - dicewareGenerator.setWordCount(words); + if (parser.value(words).isEmpty()) { + dicewareGenerator.setWordCount(PassphraseGenerator::DefaultWordCount); + } else { + int wordcount = parser.value(words).toInt(); + dicewareGenerator.setWordCount(wordcount); + } if (!parser.value(wordlistFile).isEmpty()) { dicewareGenerator.setWordList(parser.value(wordlistFile)); diff --git a/src/cli/PassGen.cpp b/src/cli/Generate.cpp similarity index 94% rename from src/cli/PassGen.cpp rename to src/cli/Generate.cpp index 900909559..3588cb421 100644 --- a/src/cli/PassGen.cpp +++ b/src/cli/Generate.cpp @@ -18,24 +18,24 @@ #include #include -#include "PassGen.h" +#include "Generate.h" #include #include #include "core/PasswordGenerator.h" -PassGen::PassGen() +Generate::Generate() { - this->name = QString("passgen"); + this->name = QString("generate"); this->description = QObject::tr("Generate a new random password."); } -PassGen::~PassGen() +Generate::~Generate() { } -int PassGen::execute(QStringList arguments) +int Generate::execute(QStringList arguments) { QTextStream inputTextStream(stdin, QIODevice::ReadOnly); QTextStream outputTextStream(stdout, QIODevice::WriteOnly); @@ -65,7 +65,7 @@ int PassGen::execute(QStringList arguments) const QStringList args = parser.positionalArguments(); if (args.size() != 0) { - outputTextStream << parser.helpText().replace("keepassxc-cli", "keepassxc-cli passgen"); + outputTextStream << parser.helpText().replace("keepassxc-cli", "keepassxc-cli generate"); return EXIT_FAILURE; } @@ -99,7 +99,7 @@ int PassGen::execute(QStringList arguments) passwordGenerator.setCharClasses(classes); if (!passwordGenerator.isValid()) { - outputTextStream << parser.helpText().replace("keepassxc-cli", "keepassxc-cli passgen"); + outputTextStream << parser.helpText().replace("keepassxc-cli", "keepassxc-cli generate"); return EXIT_FAILURE; } diff --git a/src/cli/PassGen.h b/src/cli/Generate.h similarity index 83% rename from src/cli/PassGen.h rename to src/cli/Generate.h index 5c0b33aeb..de6a8ea11 100644 --- a/src/cli/PassGen.h +++ b/src/cli/Generate.h @@ -15,17 +15,17 @@ * along with this program. If not, see . */ -#ifndef KEEPASSXC_PASSGEN_H -#define KEEPASSXC_PASSGEN_H +#ifndef KEEPASSXC_GENERATE_H +#define KEEPASSXC_GENERATE_H #include "Command.h" -class PassGen : public Command +class Generate : public Command { public: - PassGen(); - ~PassGen(); + Generate(); + ~Generate(); int execute(QStringList arguments); }; -#endif // KEEPASSXC_PASSGEN_H +#endif // KEEPASSXC_GENERATE_H