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/>.
21
#include "core/Group.h"
23
#include <QCommandLineParser>
25
const QCommandLineOption List::RecursiveOption =
26
QCommandLineOption(QStringList() << "R"
28
QObject::tr("Recursively list the elements of the group."));
30
const QCommandLineOption List::FlattenOption = QCommandLineOption(QStringList() << "f"
32
QObject::tr("Flattens the output to single lines."));
37
description = QObject::tr("List database entries.");
38
options.append(List::RecursiveOption);
39
options.append(List::FlattenOption);
40
optionalArguments.append(
41
{QString("group"), QObject::tr("Path of the group to list. Default is /"), QString("[group]")});
44
int List::executeWithDatabase(QSharedPointer<Database> database, QSharedPointer<QCommandLineParser> parser)
46
auto& out = Utils::STDOUT;
47
auto& err = Utils::STDERR;
49
const QStringList args = parser->positionalArguments();
50
bool recursive = parser->isSet(List::RecursiveOption);
51
bool flatten = parser->isSet(List::FlattenOption);
53
// No group provided, defaulting to root group.
54
if (args.size() == 1) {
55
out << database->rootGroup()->print(recursive, flatten) << flush;
59
const QString& groupPath = args.at(1);
60
Group* group = database->rootGroup()->findGroupByPath(groupPath);
62
err << QObject::tr("Cannot find group %1.").arg(groupPath) << endl;
66
out << group->print(recursive, flatten) << flush;