From 992d8a90c746f31ba77ada572d1e1c88ab299d79 Mon Sep 17 00:00:00 2001 From: Louis-Bertrand Varin Date: Thu, 2 Feb 2017 17:54:39 -0500 Subject: [PATCH] Migrate entropy-meter to keepassxc-cli --- CMakeLists.txt | 1 - src/cli/CMakeLists.txt | 2 ++ .../cli/EntropyMeter.cpp | 4 ++- src/cli/EntropyMeter.h | 27 +++++++++++++++++++ src/cli/keepassxc-cli.cpp | 16 ++++++++--- 5 files changed, 44 insertions(+), 6 deletions(-) rename utils/entropy-meter.cpp => src/cli/EntropyMeter.cpp (98%) create mode 100644 src/cli/EntropyMeter.h diff --git a/CMakeLists.txt b/CMakeLists.txt index e7d22312f..3dd435553 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -254,7 +254,6 @@ include(FeatureSummary) add_subdirectory(src) add_subdirectory(share) -add_subdirectory(utils) if(WITH_TESTS) add_subdirectory(tests) endif(WITH_TESTS) diff --git a/src/cli/CMakeLists.txt b/src/cli/CMakeLists.txt index 70dd420d5..d678ff395 100644 --- a/src/cli/CMakeLists.txt +++ b/src/cli/CMakeLists.txt @@ -16,6 +16,8 @@ set(cli_SOURCES Merge.cpp Merge.h + EntropyMeter.cpp + EntropyMeter.h Extract.cpp Extract.h) diff --git a/utils/entropy-meter.cpp b/src/cli/EntropyMeter.cpp similarity index 98% rename from utils/entropy-meter.cpp rename to src/cli/EntropyMeter.cpp index 74f6bc11a..ffaecc8e6 100644 --- a/utils/entropy-meter.cpp +++ b/src/cli/EntropyMeter.cpp @@ -6,6 +6,8 @@ Copyright (c) 2016, KeePassXC Team See zxcvbn/zxcvbn.cpp for complete COPYRIGHT Notice */ +#include "EntropyMeter.h" + #include #include #include @@ -76,7 +78,7 @@ static void calculate(const char *pwd, int advanced) } } -int main(int argc, char **argv) +int EntropyMeter::execute(int argc, char **argv) { printf("KeePassXC Entropy Meter, based on zxcvbn-c.\nEnter your password below or pass it as argv\n"); printf(" Usage: entropy-meter [-a] [pwd1 pwd2 ...]\n> "); diff --git a/src/cli/EntropyMeter.h b/src/cli/EntropyMeter.h new file mode 100644 index 000000000..5034b9660 --- /dev/null +++ b/src/cli/EntropyMeter.h @@ -0,0 +1,27 @@ +/* + * Copyright (C) 2017 KeePassXC Team + * + * 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 + * the Free Software Foundation, either version 2 or (at your option) + * version 3 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef KEEPASSXC_ENTROPYMETER_H +#define KEEPASSXC_ENTROPYMETER_H + +class EntropyMeter +{ +public: + static int execute(int argc, char** argv); +}; + +#endif // KEEPASSXC_ENTROPYMETER_H diff --git a/src/cli/keepassxc-cli.cpp b/src/cli/keepassxc-cli.cpp index e745dd09f..e8719d9c2 100644 --- a/src/cli/keepassxc-cli.cpp +++ b/src/cli/keepassxc-cli.cpp @@ -23,6 +23,7 @@ #include #include +#include #include "config-keepassx.h" #include "core/Tools.h" #include "crypto/Crypto.h" @@ -47,15 +48,17 @@ int main(int argc, char **argv) parser.addHelpOption(); parser.addVersionOption(); - parser.process(app); + // TODO : use process once the setOptionsAfterPositionalArgumentsMode (Qt 5.6) + // is available. Until then, options passed to sub-commands won't be + // recognized by this parser. + // parser.process(app); - const QStringList args = parser.positionalArguments(); - if (args.size() < 1) { + if (argc < 2) { parser.showHelp(); return EXIT_FAILURE; } - QString commandName = args.at(0); + QString commandName = argv[1]; for (int i = 1; i < argc - 1; ++i) { argv[i] = argv[i + 1]; @@ -73,6 +76,11 @@ int main(int argc, char **argv) return Extract::execute(argc, argv); } + if (commandName == "entropy-meter") { + argv[0] = const_cast("keepassxc-cli entropy-meter"); + return EntropyMeter::execute(argc, argv); + } + qCritical("Invalid command %s.", qPrintable(commandName)); parser.showHelp(); return EXIT_FAILURE;