mirror of
https://github.com/keepassxreboot/keepassxc.git
synced 2025-08-11 07:50:31 -04:00
CLI: Add 'flatten' option to the 'ls' command (#3276)
* Fixes #925 * Add 'flatten' option to CLI ls command * Add test for Group::hierarchy() and man page for ls --flatten * Rename group sort test to align with others
This commit is contained in:
parent
1e915eef89
commit
05c11d1b7c
10 changed files with 141 additions and 19 deletions
|
@ -31,11 +31,16 @@ const QCommandLineOption List::RecursiveOption =
|
|||
<< "recursive",
|
||||
QObject::tr("Recursively list the elements of the group."));
|
||||
|
||||
const QCommandLineOption List::FlattenOption = QCommandLineOption(QStringList() << "f"
|
||||
<< "flatten",
|
||||
QObject::tr("Flattens the output to single lines."));
|
||||
|
||||
List::List()
|
||||
{
|
||||
name = QString("ls");
|
||||
description = QObject::tr("List database entries.");
|
||||
options.append(List::RecursiveOption);
|
||||
options.append(List::FlattenOption);
|
||||
optionalArguments.append(
|
||||
{QString("group"), QObject::tr("Path of the group to list. Default is /"), QString("[group]")});
|
||||
}
|
||||
|
@ -51,10 +56,11 @@ int List::executeWithDatabase(QSharedPointer<Database> database, QSharedPointer<
|
|||
|
||||
const QStringList args = parser->positionalArguments();
|
||||
bool recursive = parser->isSet(List::RecursiveOption);
|
||||
bool flatten = parser->isSet(List::FlattenOption);
|
||||
|
||||
// No group provided, defaulting to root group.
|
||||
if (args.size() == 1) {
|
||||
outputTextStream << database->rootGroup()->print(recursive) << flush;
|
||||
outputTextStream << database->rootGroup()->print(recursive, flatten) << flush;
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
|
@ -65,6 +71,6 @@ int List::executeWithDatabase(QSharedPointer<Database> database, QSharedPointer<
|
|||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
outputTextStream << group->print(recursive) << flush;
|
||||
outputTextStream << group->print(recursive, flatten) << flush;
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
|
|
@ -29,6 +29,7 @@ public:
|
|||
int executeWithDatabase(QSharedPointer<Database> db, QSharedPointer<QCommandLineParser> parser);
|
||||
|
||||
static const QCommandLineOption RecursiveOption;
|
||||
static const QCommandLineOption FlattenOption;
|
||||
};
|
||||
|
||||
#endif // KEEPASSXC_LIST_H
|
||||
|
|
|
@ -152,6 +152,8 @@ be printed to STDERR.
|
|||
.IP "-R, --recursive"
|
||||
Recursively list the elements of the group.
|
||||
|
||||
.IP "-f, --flatten"
|
||||
Flattens the output to single lines. When this option is enabled, subgroups and subentries will be displayed with a relative group path instead of indentation.
|
||||
|
||||
.SS "Generate options"
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue