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_count.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_count.cpp')
-rw-r--r-- | sinksh/syntax_modules/sink_count.cpp | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/sinksh/syntax_modules/sink_count.cpp b/sinksh/syntax_modules/sink_count.cpp index 04a9550..1edf1c2 100644 --- a/sinksh/syntax_modules/sink_count.cpp +++ b/sinksh/syntax_modules/sink_count.cpp | |||
@@ -37,12 +37,14 @@ | |||
37 | namespace SinkCount | 37 | namespace SinkCount |
38 | { | 38 | { |
39 | 39 | ||
40 | Syntax::List syntax(); | ||
41 | |||
40 | bool count(const QStringList &args, State &state) | 42 | bool count(const QStringList &args, State &state) |
41 | { | 43 | { |
42 | Sink::Query query; | 44 | Sink::Query query; |
43 | query.setId("count"); | 45 | query.setId("count"); |
44 | if (!SinkshUtils::applyFilter(query, SyntaxTree::parseOptions(args))) { | 46 | if (!SinkshUtils::applyFilter(query, SyntaxTree::parseOptions(args))) { |
45 | state.printError(QObject::tr("Options: $type $filter")); | 47 | state.printError(syntax()[0].usage()); |
46 | return false; | 48 | return false; |
47 | } | 49 | } |
48 | 50 | ||
@@ -63,7 +65,11 @@ bool count(const QStringList &args, State &state) | |||
63 | 65 | ||
64 | Syntax::List syntax() | 66 | Syntax::List syntax() |
65 | { | 67 | { |
66 | Syntax count("count", QObject::tr("Returns the number of items of a given type in a resource. Usage: count <type> <resource>"), &SinkCount::count, Syntax::EventDriven); | 68 | Syntax count("count", QObject::tr("Returns the number of items of a given type in a resource"), &SinkCount::count, Syntax::EventDriven); |
69 | |||
70 | count.addPositionalArgument({.name = "type", .help = "The entity type to count"}); | ||
71 | count.addPositionalArgument({.name = "resource", .help = "A resource id where to count", .required = false}); | ||
72 | |||
67 | count.completer = &SinkshUtils::typeCompleter; | 73 | count.completer = &SinkshUtils::typeCompleter; |
68 | 74 | ||
69 | return Syntax::List() << count; | 75 | return Syntax::List() << count; |