Migrate entropy-meter to keepassxc-cli

This commit is contained in:
Louis-Bertrand Varin 2017-02-02 17:54:39 -05:00 committed by Louis-Bertrand Varin
parent 9b92e7f8e8
commit 992d8a90c7
5 changed files with 44 additions and 6 deletions

View File

@ -254,7 +254,6 @@ include(FeatureSummary)
add_subdirectory(src) add_subdirectory(src)
add_subdirectory(share) add_subdirectory(share)
add_subdirectory(utils)
if(WITH_TESTS) if(WITH_TESTS)
add_subdirectory(tests) add_subdirectory(tests)
endif(WITH_TESTS) endif(WITH_TESTS)

View File

@ -16,6 +16,8 @@
set(cli_SOURCES set(cli_SOURCES
Merge.cpp Merge.cpp
Merge.h Merge.h
EntropyMeter.cpp
EntropyMeter.h
Extract.cpp Extract.cpp
Extract.h) Extract.h)

View File

@ -6,6 +6,8 @@ Copyright (c) 2016, KeePassXC Team
See zxcvbn/zxcvbn.cpp for complete COPYRIGHT Notice See zxcvbn/zxcvbn.cpp for complete COPYRIGHT Notice
*/ */
#include "EntropyMeter.h"
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <stdlib.h> #include <stdlib.h>
@ -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("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> "); printf(" Usage: entropy-meter [-a] [pwd1 pwd2 ...]\n> ");

27
src/cli/EntropyMeter.h Normal file
View File

@ -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 <http://www.gnu.org/licenses/>.
*/
#ifndef KEEPASSXC_ENTROPYMETER_H
#define KEEPASSXC_ENTROPYMETER_H
class EntropyMeter
{
public:
static int execute(int argc, char** argv);
};
#endif // KEEPASSXC_ENTROPYMETER_H

View File

@ -23,6 +23,7 @@
#include <cli/Merge.h> #include <cli/Merge.h>
#include <cli/Extract.h> #include <cli/Extract.h>
#include <cli/EntropyMeter.h>
#include "config-keepassx.h" #include "config-keepassx.h"
#include "core/Tools.h" #include "core/Tools.h"
#include "crypto/Crypto.h" #include "crypto/Crypto.h"
@ -47,15 +48,17 @@ int main(int argc, char **argv)
parser.addHelpOption(); parser.addHelpOption();
parser.addVersionOption(); 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 (argc < 2) {
if (args.size() < 1) {
parser.showHelp(); parser.showHelp();
return EXIT_FAILURE; return EXIT_FAILURE;
} }
QString commandName = args.at(0); QString commandName = argv[1];
for (int i = 1; i < argc - 1; ++i) { for (int i = 1; i < argc - 1; ++i) {
argv[i] = argv[i + 1]; argv[i] = argv[i + 1];
@ -73,6 +76,11 @@ int main(int argc, char **argv)
return Extract::execute(argc, argv); return Extract::execute(argc, argv);
} }
if (commandName == "entropy-meter") {
argv[0] = const_cast<char*>("keepassxc-cli entropy-meter");
return EntropyMeter::execute(argc, argv);
}
qCritical("Invalid command %s.", qPrintable(commandName)); qCritical("Invalid command %s.", qPrintable(commandName));
parser.showHelp(); parser.showHelp();
return EXIT_FAILURE; return EXIT_FAILURE;