Refactoring : Introducing Command class for CLI commands (#778)

This commit is contained in:
louib
2017-07-17 15:16:53 -04:00
committed by GitHub
parent 99e3af8ff7
commit 3b23e68540
19 changed files with 356 additions and 165 deletions

View File

@@ -26,25 +26,41 @@
#include <QStringList>
#include <QTextStream>
#include "cli/PasswordInput.h"
#include "core/Database.h"
#include "format/KeePass2Reader.h"
#include "keys/CompositeKey.h"
#include "cli/PasswordInput.h"
Extract::Extract()
{
this->name = QString("extract");
this->description = QObject::tr("Extract and print the content of a database.");
}
Extract::~Extract()
{
}
int Extract::execute(int argc, char** argv)
{
QStringList arguments;
// Skipping the first argument (keepassxc).
for (int i = 1; i < argc; ++i) {
arguments << QString(argv[i]);
}
QCoreApplication app(argc, argv);
QTextStream out(stdout);
QCommandLineParser parser;
parser.setApplicationDescription(
QCoreApplication::translate("main", "Extract and print the content of a database."));
parser.addPositionalArgument("database", QCoreApplication::translate("main", "Path of the database to extract."));
parser.process(app);
parser.setApplicationDescription(this->description);
parser.addPositionalArgument("database", QObject::tr("Path of the database to extract."));
parser.process(arguments);
const QStringList args = parser.positionalArguments();
if (args.size() != 1) {
parser.showHelp(EXIT_FAILURE);
out << parser.helpText().replace("keepassxc-cli", "keepassxc-cli extract");
return EXIT_FAILURE;
}
out << "Insert the database password\n> ";