add command line option --pw-stdin to accept password from stdin

This commit is contained in:
Jack Thomasson 2016-10-24 12:22:02 -06:00
parent 7c4129033a
commit 7000e80465

View File

@ -17,6 +17,7 @@
#include <QCommandLineParser> #include <QCommandLineParser>
#include <QFile> #include <QFile>
#include <QTextStream>
#include "config-keepassx.h" #include "config-keepassx.h"
#include "core/Config.h" #include "core/Config.h"
@ -61,11 +62,14 @@ int main(int argc, char** argv)
QCommandLineOption keyfileOption("keyfile", QCommandLineOption keyfileOption("keyfile",
QCoreApplication::translate("main", "key file of the database"), QCoreApplication::translate("main", "key file of the database"),
"keyfile"); "keyfile");
QCommandLineOption pwstdinOption("pw-stdin",
QCoreApplication::translate("main", "read password of the database from stdin"));
parser.addHelpOption(); parser.addHelpOption();
parser.addVersionOption(); parser.addVersionOption();
parser.addOption(configOption); parser.addOption(configOption);
parser.addOption(keyfileOption); parser.addOption(keyfileOption);
parser.addOption(pwstdinOption);
parser.process(app); parser.process(app);
const QStringList args = parser.positionalArguments(); const QStringList args = parser.positionalArguments();
@ -90,7 +94,12 @@ int main(int argc, char** argv)
for (int ii=0; ii < args.length(); ii++) { for (int ii=0; ii < args.length(); ii++) {
QString filename = args[ii]; QString filename = args[ii];
if (!filename.isEmpty() && QFile::exists(filename)) { if (!filename.isEmpty() && QFile::exists(filename)) {
mainWindow.openDatabase(filename, QString(), parser.value(keyfileOption)); QString password;
if (parser.isSet(pwstdinOption)) {
static QTextStream in(stdin, QIODevice::ReadOnly);
password = in.readLine();
}
mainWindow.openDatabase(filename, password, parser.value(keyfileOption));
} }
} }