mirror of
https://github.com/keepassxreboot/keepassxc.git
synced 2024-10-01 01:26:01 -04:00
Use QCommandLineParser
This commit is contained in:
parent
798041fe11
commit
d7ed33809f
@ -17,6 +17,7 @@
|
|||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#include <QCommandLineParser>
|
||||||
#include <QCoreApplication>
|
#include <QCoreApplication>
|
||||||
#include <QFile>
|
#include <QFile>
|
||||||
#include <QStringList>
|
#include <QStringList>
|
||||||
@ -33,8 +34,16 @@ int main(int argc, char **argv)
|
|||||||
{
|
{
|
||||||
QCoreApplication app(argc, argv);
|
QCoreApplication app(argc, argv);
|
||||||
|
|
||||||
if (app.arguments().size() != 2) {
|
QCommandLineParser parser;
|
||||||
qCritical("Usage: kdbx-extract <kdbx file>");
|
parser.setApplicationDescription(QCoreApplication::translate("main",
|
||||||
|
"Extract and print a KeePassXC database file."));
|
||||||
|
parser.addPositionalArgument("database", QCoreApplication::translate("main", "path of the database to extract."));
|
||||||
|
parser.addHelpOption();
|
||||||
|
parser.process(app);
|
||||||
|
|
||||||
|
const QStringList args = parser.positionalArguments();
|
||||||
|
if (args.size() != 1) {
|
||||||
|
parser.showHelp();
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -46,13 +55,14 @@ int main(int argc, char **argv)
|
|||||||
QString line = inputTextStream.readLine();
|
QString line = inputTextStream.readLine();
|
||||||
CompositeKey key = CompositeKey::readFromLine(line);
|
CompositeKey key = CompositeKey::readFromLine(line);
|
||||||
|
|
||||||
QFile dbFile(app.arguments().at(1));
|
QString databaseFilename = args.at(0);
|
||||||
|
QFile dbFile(databaseFilename);
|
||||||
if (!dbFile.exists()) {
|
if (!dbFile.exists()) {
|
||||||
qCritical("File does not exist.");
|
qCritical("File %s does not exist.", qPrintable(databaseFilename));
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
if (!dbFile.open(QIODevice::ReadOnly)) {
|
if (!dbFile.open(QIODevice::ReadOnly)) {
|
||||||
qCritical("Unable to open file.");
|
qCritical("Unable to open file %s.", qPrintable(databaseFilename));
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user