From d7ed33809f1bf8f5481cd43d7bfbe9e8b5d38398 Mon Sep 17 00:00:00 2001 From: Louis-Bertrand Varin Date: Sat, 14 Jan 2017 14:08:10 -0500 Subject: [PATCH] Use QCommandLineParser --- utils/kdbx-extract.cpp | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/utils/kdbx-extract.cpp b/utils/kdbx-extract.cpp index 6116b0365..255f5d003 100644 --- a/utils/kdbx-extract.cpp +++ b/utils/kdbx-extract.cpp @@ -17,6 +17,7 @@ #include +#include #include #include #include @@ -33,8 +34,16 @@ int main(int argc, char **argv) { QCoreApplication app(argc, argv); - if (app.arguments().size() != 2) { - qCritical("Usage: kdbx-extract "); + 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; } @@ -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; }