From e9612ee9e6fcb14e43102c2636f5f8b4d2e1d968 Mon Sep 17 00:00:00 2001 From: thez3ro Date: Sun, 21 Jan 2018 02:32:46 +0100 Subject: [PATCH] use default password lenght + minor fixes --- src/cli/Diceware.cpp | 4 ++-- src/cli/PassGen.cpp | 15 +++++++++++---- src/cli/keepassxc-cli.1 | 2 +- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/cli/Diceware.cpp b/src/cli/Diceware.cpp index ddc8f43a5..361be1625 100644 --- a/src/cli/Diceware.cpp +++ b/src/cli/Diceware.cpp @@ -43,7 +43,7 @@ int Diceware::execute(QStringList arguments) QCommandLineParser parser; parser.setApplicationDescription(this->description); QCommandLineOption wordlistFile(QStringList() << "w" - << "wordlist", + << "word-list", QObject::tr("Wordlist fot the diceware generator.\n[Default: EFF English]"), QObject::tr("path")); parser.addOption(wordlistFile); @@ -68,7 +68,7 @@ int Diceware::execute(QStringList arguments) } if (!dicewareGenerator.isValid()) { - outputTextStream << parser.helpText().replace("keepassxc-cli", "keepassxc-cli passgen"); + outputTextStream << parser.helpText().replace("keepassxc-cli", "keepassxc-cli diceware"); return EXIT_FAILURE; } diff --git a/src/cli/PassGen.cpp b/src/cli/PassGen.cpp index 036f08db9..428554dc6 100644 --- a/src/cli/PassGen.cpp +++ b/src/cli/PassGen.cpp @@ -42,6 +42,10 @@ int PassGen::execute(QStringList arguments) QCommandLineParser parser; parser.setApplicationDescription(this->description); + QCommandLineOption len(QStringList() << "L" << "length", + QObject::tr("Length of the generated password."), + QObject::tr("length")); + parser.addOption(len); QCommandLineOption lower(QStringList() << "l", QObject::tr("Use lowercase in the generated password.")); parser.addOption(lower); @@ -57,19 +61,22 @@ int PassGen::execute(QStringList arguments) QCommandLineOption extended(QStringList() << "e", QObject::tr("Use extended ascii in the generated password.")); parser.addOption(extended); - parser.addPositionalArgument("length", QObject::tr("Length of the generated password.")); parser.process(arguments); const QStringList args = parser.positionalArguments(); - if (args.size() != 1) { + if (args.size() != 0) { outputTextStream << parser.helpText().replace("keepassxc-cli", "keepassxc-cli passgen"); return EXIT_FAILURE; } PasswordGenerator passwordGenerator; - int length = args.at(0).toInt(); - passwordGenerator.setLength(length); + if (parser.value(len).isEmpty()) { + passwordGenerator.setLength(PasswordGenerator::DefaultLength); + } else { + int length = parser.value(len).toInt(); + passwordGenerator.setLength(length); + } PasswordGenerator::CharClasses classes = 0x0; diff --git a/src/cli/keepassxc-cli.1 b/src/cli/keepassxc-cli.1 index 6a772e7cd..ec8d35c4c 100644 --- a/src/cli/keepassxc-cli.1 +++ b/src/cli/keepassxc-cli.1 @@ -112,7 +112,7 @@ specified, a summary of the default attributes is given. .SS "Diceware options" -.IP "-w, --wordlist " +.IP "-w, --word-list " Path of the wordlist for the diceware generator. The wordlist must have > 1000 words, otherwise the program will fail. If the wordlist has < 4000 words a warning will be printed to STDERR.