2
* Copyright (C) 2019 KeePassXC Team <team@keepassxc.org>
4
* This program is free software: you can redistribute it and/or modify
5
* it under the terms of the GNU General Public License as published by
6
* the Free Software Foundation, either version 2 or (at your option)
7
* version 3 of the License.
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
14
* You should have received a copy of the GNU General Public License
15
* along with this program. If not, see <http://www.gnu.org/licenses/>.
18
#include "DatabaseCommand.h"
21
#include "config-keepassx.h"
23
#include <QCommandLineParser>
25
DatabaseCommand::DatabaseCommand()
27
positionalArguments.append({QString("database"), QObject::tr("Path of the database."), QString("")});
28
options.append(Command::KeyFileOption);
29
options.append(Command::NoPasswordOption);
31
options.append(Command::YubiKeyOption);
35
int DatabaseCommand::execute(const QStringList& arguments)
37
QStringList amendedArgs(arguments);
38
if (currentDatabase) {
39
amendedArgs.insert(1, currentDatabase->filePath());
41
QSharedPointer<QCommandLineParser> parser = getCommandLineParser(amendedArgs);
43
if (parser.isNull()) {
47
QStringList args = parser->positionalArguments();
48
auto db = currentDatabase;
50
// It would be nice to update currentDatabase here, but the CLI tests frequently
51
// re-use Command objects to exercise non-interactive behavior. Updating the current
52
// database confuses these tests. Because of this, we leave it up to the interactive
53
// mode implementation in the main command loop to update currentDatabase
54
// (see keepassxc-cli.cpp).
55
db = Utils::unlockDatabase(args.at(0),
56
!parser->isSet(Command::NoPasswordOption),
57
parser->value(Command::KeyFileOption),
59
parser->value(Command::YubiKeyOption),
63
parser->isSet(Command::QuietOption));
69
return executeWithDatabase(db, parser);