From 931400c78c80143bdb7223ddcfa36018a9923765 Mon Sep 17 00:00:00 2001 From: vi-n Date: Wed, 3 Oct 2018 19:18:34 +0200 Subject: [PATCH] Add a CLI option to list elements recursively (#2345) --- src/cli/List.cpp | 17 ++++++++++++----- src/cli/List.h | 2 +- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/cli/List.cpp b/src/cli/List.cpp index bdedaf210e..b39b3fc147 100644 --- a/src/cli/List.cpp +++ b/src/cli/List.cpp @@ -50,6 +50,11 @@ int List::execute(const QStringList& arguments) QObject::tr("Key file of the database."), QObject::tr("path")); parser.addOption(keyFile); + + QCommandLineOption recursiveOption(QStringList() << "R" + << "recursive", + QObject::tr("Recursive mode, list elements recursively")); + parser.addOption(recursiveOption); parser.process(arguments); const QStringList args = parser.positionalArguments(); @@ -58,22 +63,24 @@ int List::execute(const QStringList& arguments) return EXIT_FAILURE; } + bool recursive = parser.isSet(recursiveOption); + Database* db = Database::unlockFromStdin(args.at(0), parser.value(keyFile)); if (db == nullptr) { return EXIT_FAILURE; } if (args.size() == 2) { - return this->listGroup(db, args.at(1)); + return this->listGroup(db, recursive, args.at(1)); } - return this->listGroup(db); + return this->listGroup(db, recursive); } -int List::listGroup(Database* database, QString groupPath) +int List::listGroup(Database* database, bool recursive, QString groupPath) { QTextStream outputTextStream(stdout, QIODevice::WriteOnly); if (groupPath.isEmpty()) { - outputTextStream << database->rootGroup()->print(); + outputTextStream << database->rootGroup()->print(recursive); outputTextStream.flush(); return EXIT_SUCCESS; } @@ -84,7 +91,7 @@ int List::listGroup(Database* database, QString groupPath) return EXIT_FAILURE; } - outputTextStream << group->print(); + outputTextStream << group->print(recursive); outputTextStream.flush(); return EXIT_SUCCESS; } diff --git a/src/cli/List.h b/src/cli/List.h index 98b8b5a452..00c3769722 100644 --- a/src/cli/List.h +++ b/src/cli/List.h @@ -26,7 +26,7 @@ class List : public Command List(); ~List(); int execute(const QStringList& arguments); - int listGroup(Database* database, QString groupPath = QString("")); + int listGroup(Database* database, bool recursive, QString groupPath = QString("")); }; #endif // KEEPASSXC_LIST_H