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_remove.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_remove.cpp')
-rw-r--r-- | sinksh/syntax_modules/sink_remove.cpp | 28 |
1 files changed, 15 insertions, 13 deletions
diff --git a/sinksh/syntax_modules/sink_remove.cpp b/sinksh/syntax_modules/sink_remove.cpp index 6baa60f..999a889 100644 --- a/sinksh/syntax_modules/sink_remove.cpp +++ b/sinksh/syntax_modules/sink_remove.cpp | |||
@@ -37,20 +37,12 @@ | |||
37 | namespace SinkRemove | 37 | namespace SinkRemove |
38 | { | 38 | { |
39 | 39 | ||
40 | Syntax::List syntax(); | ||
41 | |||
40 | bool remove(const QStringList &args, State &state) | 42 | bool remove(const QStringList &args, State &state) |
41 | { | 43 | { |
42 | if (args.isEmpty()) { | ||
43 | state.printError(QObject::tr("A type is required"), "sink_remove/02"); | ||
44 | return false; | ||
45 | } | ||
46 | |||
47 | if (args.count() < 2) { | ||
48 | state.printError(QObject::tr("A resource ID is required to remove items"), "sink_remove/03"); | ||
49 | return false; | ||
50 | } | ||
51 | |||
52 | if (args.count() < 3) { | 44 | if (args.count() < 3) { |
53 | state.printError(QObject::tr("An object ID is required to remove items"), "sink_remove/03"); | 45 | state.printError(syntax()[0].usage()); |
54 | return false; | 46 | return false; |
55 | } | 47 | } |
56 | 48 | ||
@@ -137,14 +129,24 @@ bool identity(const QStringList &args, State &state) | |||
137 | return true; | 129 | return true; |
138 | } | 130 | } |
139 | 131 | ||
140 | |||
141 | Syntax::List syntax() | 132 | Syntax::List syntax() |
142 | { | 133 | { |
143 | Syntax remove("remove", QObject::tr("Remove items in a resource"), &SinkRemove::remove); | 134 | Syntax remove("remove", QObject::tr("Remove items in a resource"), &SinkRemove::remove); |
135 | |||
136 | remove.addPositionalArgument({ .name = "type", .help = "The type of entity to remove (mail, event, etc.)" }); | ||
137 | remove.addPositionalArgument({ .name = "resourceId", .help = "The ID of the resource containing the entity" }); | ||
138 | remove.addPositionalArgument({ .name = "objectId", .help = "The ID of the entity to remove" }); | ||
139 | |||
144 | Syntax resource("resource", QObject::tr("Removes a resource"), &SinkRemove::resource, Syntax::NotInteractive); | 140 | Syntax resource("resource", QObject::tr("Removes a resource"), &SinkRemove::resource, Syntax::NotInteractive); |
141 | resource.addPositionalArgument({ .name = "id", .help = "The ID of the resource to remove" }); | ||
142 | resource.completer = &SinkshUtils::resourceCompleter; | ||
143 | |||
145 | Syntax account("account", QObject::tr("Removes a account"), &SinkRemove::account, Syntax::NotInteractive); | 144 | Syntax account("account", QObject::tr("Removes a account"), &SinkRemove::account, Syntax::NotInteractive); |
145 | account.addPositionalArgument({ .name = "id", .help = "The ID of the account to remove" }); | ||
146 | |||
146 | Syntax identity("identity", QObject::tr("Removes an identity"), &SinkRemove::identity, Syntax::NotInteractive); | 147 | Syntax identity("identity", QObject::tr("Removes an identity"), &SinkRemove::identity, Syntax::NotInteractive); |
147 | resource.completer = &SinkshUtils::resourceCompleter; | 148 | identity.addPositionalArgument({ .name = "id", .help = "The ID of the account to remove" }); |
149 | |||
148 | remove.children << resource << account << identity; | 150 | remove.children << resource << account << identity; |
149 | 151 | ||
150 | return Syntax::List() << remove; | 152 | return Syntax::List() << remove; |