diff options
author | Rémi Nicole <nicole@kolabsystems.com> | 2018-08-03 16:59:16 +0200 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2018-08-03 17:10:31 +0200 |
commit | 50bed81038f10091d35c5719df8078612393ae95 (patch) | |
tree | e4a3b634118b2b1b9fd88203902e934299deac9b /sinksh/syntax_modules/sink_list.cpp | |
parent | ad3dc221273100ba61828f993f1d1c8a1272d665 (diff) | |
download | sink-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_list.cpp')
-rw-r--r-- | sinksh/syntax_modules/sink_list.cpp | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/sinksh/syntax_modules/sink_list.cpp b/sinksh/syntax_modules/sink_list.cpp index 32fae4f..eef188b 100644 --- a/sinksh/syntax_modules/sink_list.cpp +++ b/sinksh/syntax_modules/sink_list.cpp | |||
@@ -39,6 +39,8 @@ | |||
39 | namespace SinkList | 39 | namespace SinkList |
40 | { | 40 | { |
41 | 41 | ||
42 | Syntax::List syntax(); | ||
43 | |||
42 | static QByteArray compressId(bool compress, const QByteArray &id) | 44 | static QByteArray compressId(bool compress, const QByteArray &id) |
43 | { | 45 | { |
44 | if (!compress) { | 46 | if (!compress) { |
@@ -117,7 +119,7 @@ QStringList printToList(const Sink::ApplicationDomain::ApplicationDomainType &o, | |||
117 | bool list(const QStringList &args_, State &state) | 119 | bool list(const QStringList &args_, State &state) |
118 | { | 120 | { |
119 | if (args_.isEmpty()) { | 121 | if (args_.isEmpty()) { |
120 | state.printError(QObject::tr("Options: $type [--resource $resource] [--compact] [--filter $property=$value] [--id $id] [--showall|--show $property] [--reduce $reduceProperty:$selectorProperty] [--sort $sortProperty] [--limit $count]")); | 122 | state.printError(syntax()[0].usage()); |
121 | return false; | 123 | return false; |
122 | } | 124 | } |
123 | 125 | ||
@@ -127,7 +129,7 @@ bool list(const QStringList &args_, State &state) | |||
127 | Sink::Query query; | 129 | Sink::Query query; |
128 | query.setId("list"); | 130 | query.setId("list"); |
129 | if (!SinkshUtils::applyFilter(query, options)) { | 131 | if (!SinkshUtils::applyFilter(query, options)) { |
130 | state.printError(QObject::tr("Options: $type [--resource $resource] [--compact] [--filter $property=$value] [--showall|--show $property]")); | 132 | state.printError(syntax()[0].usage()); |
131 | return false; | 133 | return false; |
132 | } | 134 | } |
133 | 135 | ||
@@ -198,6 +200,18 @@ bool list(const QStringList &args_, State &state) | |||
198 | Syntax::List syntax() | 200 | Syntax::List syntax() |
199 | { | 201 | { |
200 | Syntax list("list", QObject::tr("List all resources, or the contents of one or more resources."), &SinkList::list, Syntax::NotInteractive); | 202 | Syntax list("list", QObject::tr("List all resources, or the contents of one or more resources."), &SinkList::list, Syntax::NotInteractive); |
203 | |||
204 | list.addPositionalArgument({.name = "type", .help = "The type of content to list (resource, identity, account, mail, etc.)"}); | ||
205 | list.addParameter("resource", { .name = "resource", .help = "List only the content of the given resource" }); | ||
206 | list.addFlag("compact", "Use a compact view (reduces the size of IDs)"); | ||
207 | list.addParameter("filter", { .name = "property=$value", .help = "Filter the results" }); | ||
208 | list.addParameter("id", { .name = "id", .help = "List only the content with the given ID" }); | ||
209 | list.addFlag("showall", "Show all properties"); | ||
210 | list.addParameter("show", { .name = "property", .help = "Only show the given property" }); | ||
211 | list.addParameter("reduce", { .name = "property:$selectorProperty", .help = "Combine the result with the same $property, sorted by $selectorProperty" }); | ||
212 | list.addParameter("sort", { .name = "property", .help = "Sort the results according to the given property" }); | ||
213 | list.addParameter("limit", { .name = "count", .help = "Limit the results" }); | ||
214 | |||
201 | list.completer = &SinkshUtils::resourceOrTypeCompleter; | 215 | list.completer = &SinkshUtils::resourceOrTypeCompleter; |
202 | return Syntax::List() << list; | 216 | return Syntax::List() << list; |
203 | } | 217 | } |