Merge pull request #54 from jkt628/develop

add command line option --pw-stdin to accept password from stdin
This commit is contained in:
Jonathan White 2016-10-24 18:15:41 -04:00 committed by GitHub
commit cf2bbbfef1

View File

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