keepassxc

Форк
0
/
List.cpp 
68 строк · 2.5 Кб
1
/*
2
 *  Copyright (C) 2019 KeePassXC Team <team@keepassxc.org>
3
 *
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.
8
 *
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.
13
 *
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/>.
16
 */
17

18
#include "List.h"
19

20
#include "Utils.h"
21
#include "core/Group.h"
22

23
#include <QCommandLineParser>
24

25
const QCommandLineOption List::RecursiveOption =
26
    QCommandLineOption(QStringList() << "R"
27
                                     << "recursive",
28
                       QObject::tr("Recursively list the elements of the group."));
29

30
const QCommandLineOption List::FlattenOption = QCommandLineOption(QStringList() << "f"
31
                                                                                << "flatten",
32
                                                                  QObject::tr("Flattens the output to single lines."));
33

34
List::List()
35
{
36
    name = QString("ls");
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]")});
42
}
43

44
int List::executeWithDatabase(QSharedPointer<Database> database, QSharedPointer<QCommandLineParser> parser)
45
{
46
    auto& out = Utils::STDOUT;
47
    auto& err = Utils::STDERR;
48

49
    const QStringList args = parser->positionalArguments();
50
    bool recursive = parser->isSet(List::RecursiveOption);
51
    bool flatten = parser->isSet(List::FlattenOption);
52

53
    // No group provided, defaulting to root group.
54
    if (args.size() == 1) {
55
        out << database->rootGroup()->print(recursive, flatten) << flush;
56
        return EXIT_SUCCESS;
57
    }
58

59
    const QString& groupPath = args.at(1);
60
    Group* group = database->rootGroup()->findGroupByPath(groupPath);
61
    if (!group) {
62
        err << QObject::tr("Cannot find group %1.").arg(groupPath) << endl;
63
        return EXIT_FAILURE;
64
    }
65

66
    out << group->print(recursive, flatten) << flush;
67
    return EXIT_SUCCESS;
68
}
69

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.