renamed passgen to generate and use diceware default wordcount

This commit is contained in:
thez3ro 2018-01-31 00:50:02 +01:00
parent e57a2e0fa9
commit 4782b20d61
No known key found for this signature in database
GPG Key ID: F628F9E41DD7C073
5 changed files with 28 additions and 21 deletions

View File

@ -28,14 +28,14 @@ set(cli_SOURCES
Estimate.h Estimate.h
Extract.cpp Extract.cpp
Extract.h Extract.h
Generate.cpp
Generate.h
List.cpp List.cpp
List.h List.h
Locate.cpp Locate.cpp
Locate.h Locate.h
Merge.cpp Merge.cpp
Merge.h Merge.h
PassGen.cpp
PassGen.h
Remove.cpp Remove.cpp
Remove.h Remove.h
Show.cpp Show.cpp

View File

@ -28,10 +28,10 @@
#include "Edit.h" #include "Edit.h"
#include "Estimate.h" #include "Estimate.h"
#include "Extract.h" #include "Extract.h"
#include "Generate.h"
#include "List.h" #include "List.h"
#include "Locate.h" #include "Locate.h"
#include "Merge.h" #include "Merge.h"
#include "PassGen.h"
#include "Remove.h" #include "Remove.h"
#include "Show.h" #include "Show.h"
@ -67,10 +67,10 @@ void populateCommands()
commands.insert(QString("edit"), new Edit()); commands.insert(QString("edit"), new Edit());
commands.insert(QString("estimate"), new Estimate()); commands.insert(QString("estimate"), new Estimate());
commands.insert(QString("extract"), new Extract()); commands.insert(QString("extract"), new Extract());
commands.insert(QString("generate"), new Generate());
commands.insert(QString("locate"), new Locate()); commands.insert(QString("locate"), new Locate());
commands.insert(QString("ls"), new List()); commands.insert(QString("ls"), new List());
commands.insert(QString("merge"), new Merge()); commands.insert(QString("merge"), new Merge());
commands.insert(QString("passgen"), new PassGen());
commands.insert(QString("rm"), new Remove()); commands.insert(QString("rm"), new Remove());
commands.insert(QString("show"), new Show()); commands.insert(QString("show"), new Show());
} }

View File

@ -42,24 +42,31 @@ int Diceware::execute(QStringList arguments)
QCommandLineParser parser; QCommandLineParser parser;
parser.setApplicationDescription(this->description); 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" QCommandLineOption wordlistFile(QStringList() << "w"
<< "word-list", << "word-list",
QObject::tr("Wordlist fot the diceware generator.\n[Default: EFF English]"), QObject::tr("Wordlist fot the diceware generator.\n[Default: EFF English]"),
QObject::tr("path")); QObject::tr("path"));
parser.addOption(wordlistFile); parser.addOption(wordlistFile);
parser.addPositionalArgument("words", QObject::tr("Word count for the diceware generator."));
parser.process(arguments); parser.process(arguments);
const QStringList args = parser.positionalArguments(); const QStringList args = parser.positionalArguments();
if (args.size() != 1) { if (args.size() != 0) {
outputTextStream << parser.helpText().replace("keepassxc-cli", "keepassxc-cli diceware"); outputTextStream << parser.helpText().replace("keepassxc-cli", "keepassxc-cli diceware");
return EXIT_FAILURE; return EXIT_FAILURE;
} }
PassphraseGenerator dicewareGenerator; PassphraseGenerator dicewareGenerator;
int words = args.at(0).toInt(); if (parser.value(words).isEmpty()) {
dicewareGenerator.setWordCount(words); dicewareGenerator.setWordCount(PassphraseGenerator::DefaultWordCount);
} else {
int wordcount = parser.value(words).toInt();
dicewareGenerator.setWordCount(wordcount);
}
if (!parser.value(wordlistFile).isEmpty()) { if (!parser.value(wordlistFile).isEmpty()) {
dicewareGenerator.setWordList(parser.value(wordlistFile)); dicewareGenerator.setWordList(parser.value(wordlistFile));

View File

@ -18,24 +18,24 @@
#include <cstdlib> #include <cstdlib>
#include <stdio.h> #include <stdio.h>
#include "PassGen.h" #include "Generate.h"
#include <QCommandLineParser> #include <QCommandLineParser>
#include <QTextStream> #include <QTextStream>
#include "core/PasswordGenerator.h" #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."); 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 inputTextStream(stdin, QIODevice::ReadOnly);
QTextStream outputTextStream(stdout, QIODevice::WriteOnly); QTextStream outputTextStream(stdout, QIODevice::WriteOnly);
@ -65,7 +65,7 @@ int PassGen::execute(QStringList arguments)
const QStringList args = parser.positionalArguments(); const QStringList args = parser.positionalArguments();
if (args.size() != 0) { 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; return EXIT_FAILURE;
} }
@ -99,7 +99,7 @@ int PassGen::execute(QStringList arguments)
passwordGenerator.setCharClasses(classes); passwordGenerator.setCharClasses(classes);
if (!passwordGenerator.isValid()) { if (!passwordGenerator.isValid()) {
outputTextStream << parser.helpText().replace("keepassxc-cli", "keepassxc-cli passgen"); outputTextStream << parser.helpText().replace("keepassxc-cli", "keepassxc-cli generate");
return EXIT_FAILURE; return EXIT_FAILURE;
} }

View File

@ -15,17 +15,17 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef KEEPASSXC_PASSGEN_H #ifndef KEEPASSXC_GENERATE_H
#define KEEPASSXC_PASSGEN_H #define KEEPASSXC_GENERATE_H
#include "Command.h" #include "Command.h"
class PassGen : public Command class Generate : public Command
{ {
public: public:
PassGen(); Generate();
~PassGen(); ~Generate();
int execute(QStringList arguments); int execute(QStringList arguments);
}; };
#endif // KEEPASSXC_PASSGEN_H #endif // KEEPASSXC_GENERATE_H