Skip to content

Commit

Permalink
Add a CLI option to list elements recursively (keepassxreboot#2345)
Browse files Browse the repository at this point in the history
  • Loading branch information
coelebs committed Nov 13, 2018
1 parent c1e9f45 commit 931400c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
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

0 comments on commit 931400c

Please sign in to comment.