summaryrefslogtreecommitdiffstats
path: root/sinksh/syntax_modules/sink_livequery.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_livequery.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_livequery.cpp')
-rw-r--r--sinksh/syntax_modules/sink_livequery.cpp33
1 files changed, 22 insertions, 11 deletions
diff --git a/sinksh/syntax_modules/sink_livequery.cpp b/sinksh/syntax_modules/sink_livequery.cpp
index e9e85ec..0acaaeb 100644
--- a/sinksh/syntax_modules/sink_livequery.cpp
+++ b/sinksh/syntax_modules/sink_livequery.cpp
@@ -38,10 +38,30 @@
38namespace SinkLiveQuery 38namespace SinkLiveQuery
39{ 39{
40 40
41bool livequery(const QStringList &args_, State &state);
42
43Syntax::List syntax()
44{
45 Syntax list("livequery", QObject::tr("Run a livequery."), &SinkLiveQuery::livequery, Syntax::EventDriven);
46
47 list.addPositionalArgument({ .name = "type", .help = "The type to run the livequery on" });
48 list.addParameter("resource", { .name = "resource", .help = "Filter the livequery to the given resource" });
49 list.addFlag("compact", "Use a compact view (reduces the size of IDs)");
50 list.addParameter("filter", { .name = "property=$value", .help = "Filter the results" });
51 list.addParameter("id", { .name = "id", .help = "List only the content with the given ID" });
52 list.addFlag("showall", "Show all properties");
53 list.addParameter("show", { .name = "property", .help = "Only show the given property" });
54
55 list.completer = &SinkshUtils::resourceOrTypeCompleter;
56 return Syntax::List() << list;
57}
58
59REGISTER_SYNTAX(SinkLiveQuery)
60
41bool livequery(const QStringList &args_, State &state) 61bool livequery(const QStringList &args_, State &state)
42{ 62{
43 if (args_.isEmpty()) { 63 if (args_.isEmpty()) {
44 state.printError(QObject::tr("Options: $type [--resource $resource] [--compact] [--filter $property=$value] [--id $id] [--showall|--show $property]")); 64 state.printError(syntax()[0].usage());
45 return false; 65 return false;
46 } 66 }
47 67
@@ -55,7 +75,7 @@ bool livequery(const QStringList &args_, State &state)
55 query.setId("livequery"); 75 query.setId("livequery");
56 query.setFlags(Sink::Query::LiveQuery); 76 query.setFlags(Sink::Query::LiveQuery);
57 if (!SinkshUtils::applyFilter(query, options)) { 77 if (!SinkshUtils::applyFilter(query, options)) {
58 state.printError(QObject::tr("Options: $type [--resource $resource] [--compact] [--filter $property=$value] [--showall|--show $property]")); 78 state.printError(syntax()[0].usage());
59 return false; 79 return false;
60 } 80 }
61 if (options.options.contains("resource")) { 81 if (options.options.contains("resource")) {
@@ -121,13 +141,4 @@ bool livequery(const QStringList &args_, State &state)
121 return false; 141 return false;
122} 142}
123 143
124Syntax::List syntax()
125{
126 Syntax list("livequery", QObject::tr("Run a livequery."), &SinkLiveQuery::livequery, Syntax::EventDriven);
127 list.completer = &SinkshUtils::resourceOrTypeCompleter;
128 return Syntax::List() << list;
129}
130
131REGISTER_SYNTAX(SinkLiveQuery)
132
133} 144}