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

View File

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

View File

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

View File

@ -18,24 +18,24 @@
#include <cstdlib>
#include <stdio.h>
#include "PassGen.h"
#include "Generate.h"
#include <QCommandLineParser>
#include <QTextStream>
#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;
}

View File

@ -15,17 +15,17 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#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