summaryrefslogtreecommitdiffstats
path: root/sinksh/syntax_modules/sink_livequery.cpp
diff options
context:
space:
mode:
authorRémi Nicole <nicole@kolabsystems.com>2018-08-03 16:59:16 +0200
committerChristian Mollekopf <chrigi_1@fastmail.fm>2018-08-03 17:10:31 +0200
commit50bed81038f10091d35c5719df8078612393ae95 (patch)
treee4a3b634118b2b1b9fd88203902e934299deac9b /sinksh/syntax_modules/sink_livequery.cpp
parentad3dc221273100ba61828f993f1d1c8a1272d665 (diff)
downloadsink-50bed81038f10091d35c5719df8078612393ae95.tar.gz
sink-50bed81038f10091d35c5719df8078612393ae95.zip
Improve documentation of SinkSH
Summary: - Add support for positional arguments, options, flags in the syntax tree - Add automatic generation of usage string TODO: - ~~Better document the `--reduce` option in the `list` command~~ - Get the parent command for sub-commands so we could show help for `trace on` and not just `on` - Pass the syntax to the implementation of the command so commands can easily show help on wrong usage. Also, SyntaxTree could do automatic input validation in the future, this could also help. - Even with the new documentation, some command could still be confusing. Should we add some usage examples? Reviewers: cmollekopf Reviewed By: cmollekopf Tags: #sink Differential Revision: https://phabricator.kde.org/D14547
Diffstat (limited to 'sinksh/syntax_modules/sink_livequery.cpp')
-rw-r--r--sinksh/syntax_modules/sink_livequery.cpp15
1 files changed, 13 insertions, 2 deletions
diff --git a/sinksh/syntax_modules/sink_livequery.cpp b/sinksh/syntax_modules/sink_livequery.cpp
index e9e85ec..2d8d5d0 100644
--- a/sinksh/syntax_modules/sink_livequery.cpp
+++ b/sinksh/syntax_modules/sink_livequery.cpp
@@ -38,10 +38,12 @@
38namespace SinkLiveQuery 38namespace SinkLiveQuery
39{ 39{
40 40
41Syntax::List syntax();
42
41bool livequery(const QStringList &args_, State &state) 43bool livequery(const QStringList &args_, State &state)
42{ 44{
43 if (args_.isEmpty()) { 45 if (args_.isEmpty()) {
44 state.printError(QObject::tr("Options: $type [--resource $resource] [--compact] [--filter $property=$value] [--id $id] [--showall|--show $property]")); 46 state.printError(syntax()[0].usage());
45 return false; 47 return false;
46 } 48 }
47 49
@@ -55,7 +57,7 @@ bool livequery(const QStringList &args_, State &state)
55 query.setId("livequery"); 57 query.setId("livequery");
56 query.setFlags(Sink::Query::LiveQuery); 58 query.setFlags(Sink::Query::LiveQuery);
57 if (!SinkshUtils::applyFilter(query, options)) { 59 if (!SinkshUtils::applyFilter(query, options)) {
58 state.printError(QObject::tr("Options: $type [--resource $resource] [--compact] [--filter $property=$value] [--showall|--show $property]")); 60 state.printError(syntax()[0].usage());
59 return false; 61 return false;
60 } 62 }
61 if (options.options.contains("resource")) { 63 if (options.options.contains("resource")) {
@@ -124,6 +126,15 @@ bool livequery(const QStringList &args_, State &state)
124Syntax::List syntax() 126Syntax::List syntax()
125{ 127{
126 Syntax list("livequery", QObject::tr("Run a livequery."), &SinkLiveQuery::livequery, Syntax::EventDriven); 128 Syntax list("livequery", QObject::tr("Run a livequery."), &SinkLiveQuery::livequery, Syntax::EventDriven);
129
130 list.addPositionalArgument({ .name = "type", .help = "The type to run the livequery on" });
131 list.addParameter("resource", { .name = "resource", .help = "Filter the livequery to the given resource" });
132 list.addFlag("compact", "Use a compact view (reduces the size of IDs)");
133 list.addParameter("filter", { .name = "property=$value", .help = "Filter the results" });
134 list.addParameter("id", { .name = "id", .help = "List only the content with the given ID" });
135 list.addFlag("showall", "Show all properties");
136 list.addParameter("show", { .name = "property", .help = "Only show the given property" });
137
127 list.completer = &SinkshUtils::resourceOrTypeCompleter; 138 list.completer = &SinkshUtils::resourceOrTypeCompleter;
128 return Syntax::List() << list; 139 return Syntax::List() << list;
129} 140}