Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to list elements recursively in the cli #2345

Merged
merged 2 commits into from
Oct 3, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions src/cli/List.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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;
}
Expand All @@ -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;
}
2 changes: 1 addition & 1 deletion src/cli/List.h
Original file line number Diff line number Diff line change
Expand Up @@ -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