Skip to content

Commit

Permalink
Use QCommandLineParser
Browse files Browse the repository at this point in the history
  • Loading branch information
Louis-Bertrand Varin committed Jan 14, 2017
1 parent 798041f commit d7ed338
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions utils/kdbx-extract.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

#include <stdio.h>

#include <QCommandLineParser>
#include <QCoreApplication>
#include <QFile>
#include <QStringList>
Expand All @@ -33,8 +34,16 @@ int main(int argc, char **argv)
{
QCoreApplication app(argc, argv);

if (app.arguments().size() != 2) {
qCritical("Usage: kdbx-extract <kdbx file>");
QCommandLineParser parser;
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;
}

Expand All @@ -46,13 +55,14 @@ int main(int argc, char **argv)
QString line = inputTextStream.readLine();
CompositeKey key = CompositeKey::readFromLine(line);

QFile dbFile(app.arguments().at(1));
QString databaseFilename = args.at(0);
QFile dbFile(databaseFilename);
if (!dbFile.exists()) {
qCritical("File does not exist.");
qCritical("File %s does not exist.", qPrintable(databaseFilename));
return 1;
}
if (!dbFile.open(QIODevice::ReadOnly)) {
qCritical("Unable to open file.");
qCritical("Unable to open file %s.", qPrintable(databaseFilename));
return 1;
}

Expand Down

0 comments on commit d7ed338

Please sign in to comment.