summaryrefslogtreecommitdiffstats
path: root/sinksh/syntax_modules/sink_list.cpp
diff options
context:
space:
mode:
authorMinijackson <minijackson@riseup.net>2018-08-02 10:40:35 +0200
committerMinijackson <minijackson@riseup.net>2018-08-02 10:40:35 +0200
commiteb4c557efa38673eba773bda6b71a286d0c3c3b1 (patch)
tree570600682e6a21f6f5edefab880ef20f4f298e18 /sinksh/syntax_modules/sink_list.cpp
parenta24bf3db83d81d7d7677a1f0f750f208d32998a8 (diff)
downloadsink-eb4c557efa38673eba773bda6b71a286d0c3c3b1.tar.gz
sink-eb4c557efa38673eba773bda6b71a286d0c3c3b1.zip
Add subcommand/parameter/option/flag and automatic help
Diffstat (limited to 'sinksh/syntax_modules/sink_list.cpp')
-rw-r--r--sinksh/syntax_modules/sink_list.cpp37
1 files changed, 26 insertions, 11 deletions
diff --git a/sinksh/syntax_modules/sink_list.cpp b/sinksh/syntax_modules/sink_list.cpp
index 4363e6f..966548f 100644
--- a/sinksh/syntax_modules/sink_list.cpp
+++ b/sinksh/syntax_modules/sink_list.cpp
@@ -39,6 +39,30 @@
39namespace SinkList 39namespace SinkList
40{ 40{
41 41
42bool list(const QStringList &args_, State &state);
43
44Syntax::List syntax()
45{
46 Syntax list("list", QObject::tr("List all resources, or the contents of one or more resources."), &SinkList::list, Syntax::NotInteractive);
47
48 list.addPositionalArgument({.name = "type", .help = "The type of content to list (resource, identity, account, mail, etc.)"});
49 list.addParameter("resource", { .name = "resource", .help = "List only the content of the given resource" });
50 list.addFlag("compact", "Use a compact view (reduces the size of IDs)");
51 list.addParameter("filter", { .name = "property=$value", .help = "Filter the results" });
52 list.addParameter("id", { .name = "id", .help = "List only the content with the given ID" });
53 list.addFlag("showall", "Show all properties");
54 list.addParameter("show", { .name = "property", .help = "Only show the given property" });
55 // TODO: what is that?
56 list.addParameter("reduce", { .name = "property:$selectorProperty", .help = "Reduce the results" });
57 list.addParameter("sort", { .name = "property", .help = "Sort the results according to the given property" });
58 list.addParameter("limit", { .name = "count", .help = "Limit the results" });
59
60 list.completer = &SinkshUtils::resourceOrTypeCompleter;
61 return Syntax::List() << list;
62}
63
64REGISTER_SYNTAX(SinkList)
65
42static QByteArray compressId(bool compress, const QByteArray &id) 66static QByteArray compressId(bool compress, const QByteArray &id)
43{ 67{
44 if (!compress) { 68 if (!compress) {
@@ -115,7 +139,7 @@ QStringList printToList(const Sink::ApplicationDomain::ApplicationDomainType &o,
115bool list(const QStringList &args_, State &state) 139bool list(const QStringList &args_, State &state)
116{ 140{
117 if (args_.isEmpty()) { 141 if (args_.isEmpty()) {
118 state.printError(QObject::tr("Options: $type [--resource $resource] [--compact] [--filter $property=$value] [--id $id] [--showall|--show $property] [--reduce $reduceProperty:$selectorProperty] [--sort $sortProperty] [--limit $count]")); 142 state.printError(syntax()[0].usage());
119 return false; 143 return false;
120 } 144 }
121 145
@@ -125,7 +149,7 @@ bool list(const QStringList &args_, State &state)
125 Sink::Query query; 149 Sink::Query query;
126 query.setId("list"); 150 query.setId("list");
127 if (!SinkshUtils::applyFilter(query, options)) { 151 if (!SinkshUtils::applyFilter(query, options)) {
128 state.printError(QObject::tr("Options: $type [--resource $resource] [--compact] [--filter $property=$value] [--showall|--show $property]")); 152 state.printError(syntax()[0].usage());
129 return false; 153 return false;
130 } 154 }
131 155
@@ -193,13 +217,4 @@ bool list(const QStringList &args_, State &state)
193 return true; 217 return true;
194} 218}
195 219
196Syntax::List syntax()
197{
198 Syntax list("list", QObject::tr("List all resources, or the contents of one or more resources."), &SinkList::list, Syntax::NotInteractive);
199 list.completer = &SinkshUtils::resourceOrTypeCompleter;
200 return Syntax::List() << list;
201}
202
203REGISTER_SYNTAX(SinkList)
204
205} 220}