diff options
Diffstat (limited to 'src/cli/Estimate.cpp')
-rw-r--r-- | src/cli/Estimate.cpp | 39 |
1 files changed, 15 insertions, 24 deletions
diff --git a/src/cli/Estimate.cpp b/src/cli/Estimate.cpp index c278b50f3..a84e23963 100644 --- a/src/cli/Estimate.cpp +++ b/src/cli/Estimate.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2017 KeePassXC Team <team@keepassxc.org> + * Copyright (C) 2019 KeePassXC Team <team@keepassxc.org> * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -18,8 +18,6 @@ #include "Estimate.h" #include "cli/Utils.h" -#include <QCommandLineParser> - #include "cli/TextStream.h" #include <stdio.h> #include <stdlib.h> @@ -33,16 +31,20 @@ #endif #endif +const QCommandLineOption Estimate::AdvancedOption = + QCommandLineOption(QStringList() << "a" + << "advanced", + QObject::tr("Perform advanced analysis on the password.")); + Estimate::Estimate() { name = QString("estimate"); + optionalArguments.append( + {QString("password"), QObject::tr("Password for which to estimate the entropy."), QString("[password]")}); + options.append(Estimate::AdvancedOption); description = QObject::tr("Estimate the entropy of a password."); } -Estimate::~Estimate() -{ -} - static void estimate(const char* pwd, bool advanced) { TextStream out(Utils::STDOUT, QIODevice::WriteOnly); @@ -156,25 +158,14 @@ static void estimate(const char* pwd, bool advanced) int Estimate::execute(const QStringList& arguments) { - TextStream inputTextStream(Utils::STDIN, QIODevice::ReadOnly); - TextStream errorTextStream(Utils::STDERR, QIODevice::WriteOnly); - - QCommandLineParser parser; - parser.setApplicationDescription(description); - parser.addPositionalArgument("password", QObject::tr("Password for which to estimate the entropy."), "[password]"); - QCommandLineOption advancedOption(QStringList() << "a" - << "advanced", - QObject::tr("Perform advanced analysis on the password.")); - parser.addOption(advancedOption); - parser.addHelpOption(); - parser.process(arguments); - - const QStringList args = parser.positionalArguments(); - if (args.size() > 1) { - errorTextStream << parser.helpText().replace("[options]", "estimate [options]"); + QSharedPointer<QCommandLineParser> parser = getCommandLineParser(arguments); + if (parser.isNull()) { return EXIT_FAILURE; } + TextStream inputTextStream(Utils::STDIN, QIODevice::ReadOnly); + const QStringList args = parser->positionalArguments(); + QString password; if (args.size() == 1) { password = args.at(0); @@ -182,6 +173,6 @@ int Estimate::execute(const QStringList& arguments) password = inputTextStream.readLine(); } - estimate(password.toLatin1(), parser.isSet(advancedOption)); + estimate(password.toLatin1(), parser->isSet(Estimate::AdvancedOption)); return EXIT_SUCCESS; } |