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_inspect.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_inspect.cpp')
-rw-r--r-- | sinksh/syntax_modules/sink_inspect.cpp | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/sinksh/syntax_modules/sink_inspect.cpp b/sinksh/syntax_modules/sink_inspect.cpp index f9cc50a..355efa3 100644 --- a/sinksh/syntax_modules/sink_inspect.cpp +++ b/sinksh/syntax_modules/sink_inspect.cpp | |||
@@ -55,10 +55,14 @@ QString parse(const QByteArray &bytes) | |||
55 | } | 55 | } |
56 | } | 56 | } |
57 | 57 | ||
58 | Syntax::List syntax(); | ||
59 | |||
58 | bool inspect(const QStringList &args, State &state) | 60 | bool inspect(const QStringList &args, State &state) |
59 | { | 61 | { |
60 | if (args.isEmpty()) { | 62 | if (args.isEmpty()) { |
61 | state.printError(QObject::tr("Options: [--resource $resource] ([--db $db] [--filter $id] [--showinternal] | [--validaterids $type] | [--fulltext [$id]])")); | 63 | //state.printError(QObject::tr("Options: [--resource $resource] ([--db $db] [--filter $id] [--showinternal] | [--validaterids $type] | [--fulltext [$id]])")); |
64 | state.printError(syntax()[0].usage()); | ||
65 | return false; | ||
62 | } | 66 | } |
63 | auto options = SyntaxTree::parseOptions(args); | 67 | auto options = SyntaxTree::parseOptions(args); |
64 | auto resource = SinkshUtils::parseUid(options.options.value("resource").value(0).toUtf8()); | 68 | auto resource = SinkshUtils::parseUid(options.options.value("resource").value(0).toUtf8()); |
@@ -236,7 +240,21 @@ bool inspect(const QStringList &args, State &state) | |||
236 | 240 | ||
237 | Syntax::List syntax() | 241 | Syntax::List syntax() |
238 | { | 242 | { |
239 | Syntax state("inspect", QObject::tr("Inspect database for the resource requested"), &SinkInspect::inspect, Syntax::NotInteractive); | 243 | Syntax state("inspect", QObject::tr("Inspect database for the resource requested"), |
244 | &SinkInspect::inspect, Syntax::NotInteractive); | ||
245 | |||
246 | state.addParameter("resource", | ||
247 | { .name = "resource", .help = "Which resource to inspect", .required = true }); | ||
248 | state.addParameter("db", | ||
249 | { .name = "database", .help = "Which database to inspect"}); | ||
250 | state.addParameter("filter", | ||
251 | { .name = "id", .help = "A specific id to filter the results by (currently not working)"}); | ||
252 | state.addFlag("showinternal", "Show internal fields only"); | ||
253 | state.addParameter("validaterids", | ||
254 | { .name = "type", .help = "Validate remote Ids of the given type"}); | ||
255 | state.addParameter("fulltext", | ||
256 | { .name = "id", .help = "If 'id' is not given, count the number of fulltext documents. Else, print the terms of the document with the given id"}); | ||
257 | |||
240 | state.completer = &SinkshUtils::resourceCompleter; | 258 | state.completer = &SinkshUtils::resourceCompleter; |
241 | 259 | ||
242 | return Syntax::List() << state; | 260 | return Syntax::List() << state; |