keepassxc/src/cli/keepassxc-cli.cpp

93 lines
2.7 KiB
C++
Raw Normal View History

2017-01-30 19:18:35 -05:00
/*
* 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/>.
*/
2017-02-02 17:30:54 -05:00
#include <cstdlib>
2017-01-30 19:18:35 -05:00
#include <QCommandLineParser>
#include <QCoreApplication>
#include <QStringList>
2017-02-13 22:29:20 -05:00
#include <cli/List.h>
2017-02-02 17:30:54 -05:00
#include <cli/Merge.h>
#include <cli/Extract.h>
2017-02-02 17:54:39 -05:00
#include <cli/EntropyMeter.h>
2017-01-30 19:18:35 -05:00
#include "config-keepassx.h"
2017-02-02 10:33:50 -05:00
#include "core/Tools.h"
2017-01-30 19:18:35 -05:00
#include "crypto/Crypto.h"
int main(int argc, char **argv)
{
2017-02-02 10:33:50 -05:00
#ifdef QT_NO_DEBUG
Tools::disableCoreDumps();
#endif
2017-01-30 19:18:35 -05:00
if (!Crypto::init()) {
qFatal("Fatal error while testing the cryptographic functions:\n%s", qPrintable(Crypto::errorString()));
2017-02-02 17:30:54 -05:00
return EXIT_FAILURE;
2017-01-30 19:18:35 -05:00
}
QCoreApplication app(argc, argv);
app.setApplicationVersion(KEEPASSX_VERSION);
QCommandLineParser parser;
2017-02-05 13:40:40 -05:00
parser.setApplicationDescription(QCoreApplication::translate("main", "KeePassXC command line interface."));
2017-01-30 19:18:35 -05:00
parser.addPositionalArgument("command", QCoreApplication::translate("main", "Name of the command to execute."));
parser.addHelpOption();
parser.addVersionOption();
2017-02-02 17:54:39 -05:00
// 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);
2017-01-30 19:18:35 -05:00
2017-02-02 17:54:39 -05:00
if (argc < 2) {
2017-01-30 19:18:35 -05:00
parser.showHelp();
2017-02-02 17:30:54 -05:00
return EXIT_FAILURE;
2017-01-30 19:18:35 -05:00
}
2017-02-02 17:54:39 -05:00
QString commandName = argv[1];
2017-01-30 19:18:35 -05:00
2017-02-05 12:56:44 -05:00
// Removing the first cli argument before dispatching.
++argv;
2017-02-02 10:51:33 -05:00
--argc;
2017-01-30 19:18:35 -05:00
2017-02-13 22:29:20 -05:00
if (commandName == "list") {
argv[0] = const_cast<char*>("keepassxc-cli list");
return List::execute(argc, argv);
}
2017-02-02 10:51:33 -05:00
if (commandName == "merge") {
argv[0] = const_cast<char*>("keepassxc-cli merge");
2017-01-30 19:18:35 -05:00
return Merge::execute(argc, argv);
}
2017-02-02 10:51:33 -05:00
if (commandName == "extract") {
argv[0] = const_cast<char*>("keepassxc-cli extract");
2017-01-30 19:18:35 -05:00
return Extract::execute(argc, argv);
}
2017-02-02 17:54:39 -05:00
if (commandName == "entropy-meter") {
argv[0] = const_cast<char*>("keepassxc-cli entropy-meter");
return EntropyMeter::execute(argc, argv);
}
2017-01-30 19:18:35 -05:00
qCritical("Invalid command %s.", qPrintable(commandName));
parser.showHelp();
2017-02-02 17:30:54 -05:00
return EXIT_FAILURE;
2017-01-30 19:18:35 -05:00
}