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_create.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_create.cpp')
-rw-r--r-- | sinksh/syntax_modules/sink_create.cpp | 35 |
1 files changed, 25 insertions, 10 deletions
diff --git a/sinksh/syntax_modules/sink_create.cpp b/sinksh/syntax_modules/sink_create.cpp index f18a990..b1631cd 100644 --- a/sinksh/syntax_modules/sink_create.cpp +++ b/sinksh/syntax_modules/sink_create.cpp | |||
@@ -40,15 +40,12 @@ using namespace Sink; | |||
40 | namespace SinkCreate | 40 | namespace SinkCreate |
41 | { | 41 | { |
42 | 42 | ||
43 | Syntax::List syntax(); | ||
44 | |||
43 | bool create(const QStringList &allArgs, State &state) | 45 | bool create(const QStringList &allArgs, State &state) |
44 | { | 46 | { |
45 | if (allArgs.isEmpty()) { | ||
46 | state.printError(QObject::tr("A type is required"), "sinkcreate/02"); | ||
47 | return false; | ||
48 | } | ||
49 | |||
50 | if (allArgs.count() < 2) { | 47 | if (allArgs.count() < 2) { |
51 | state.printError(QObject::tr("A resource ID is required to create items"), "sinkcreate/03"); | 48 | state.printError(syntax()[0].usage()); |
52 | return false; | 49 | return false; |
53 | } | 50 | } |
54 | 51 | ||
@@ -173,15 +170,33 @@ bool identity(const QStringList &args, State &state) | |||
173 | return true; | 170 | return true; |
174 | } | 171 | } |
175 | 172 | ||
176 | |||
177 | Syntax::List syntax() | 173 | Syntax::List syntax() |
178 | { | 174 | { |
179 | Syntax::List syntax; | 175 | Syntax::List syntax; |
180 | 176 | ||
181 | Syntax create("create", QObject::tr("Create items in a resource"), &SinkCreate::create); | 177 | Syntax create("create", QObject::tr("Create items in a resource"), &SinkCreate::create); |
182 | create.children << Syntax("resource", QObject::tr("Creates a new resource"), &SinkCreate::resource); | 178 | create.addPositionalArgument({ .name = "type", .help = "The type of entity to create (mail, event, etc.)" }); |
183 | create.children << Syntax("account", QObject::tr("Creates a new account"), &SinkCreate::account); | 179 | create.addPositionalArgument({ .name = "resourceId", .help = "The ID of the resource that will contain the new entity" }); |
184 | create.children << Syntax("identity", QObject::tr("Creates a new identity"), &SinkCreate::identity); | 180 | create.addPositionalArgument( |
181 | { .name = "key value", .help = "Content of the entity", .required = false, .variadic = true }); | ||
182 | |||
183 | Syntax resource("resource", QObject::tr("Creates a new resource"), &SinkCreate::resource); | ||
184 | resource.addPositionalArgument({ .name = "type", .help = "The type of resource to create" }); | ||
185 | resource.addPositionalArgument( | ||
186 | { .name = "key value", .help = "Content of the resource", .required = false, .variadic = true }); | ||
187 | |||
188 | Syntax account("account", QObject::tr("Creates a new account"), &SinkCreate::account); | ||
189 | account.addPositionalArgument({ .name = "type", .help = "The type of account to create" }); | ||
190 | account.addPositionalArgument( | ||
191 | { .name = "key value", .help = "Content of the account", .required = false, .variadic = true }); | ||
192 | |||
193 | Syntax identity("identity", QObject::tr("Creates a new identity"), &SinkCreate::identity); | ||
194 | identity.addPositionalArgument( | ||
195 | { .name = "key value", .help = "Content of the identity", .required = false, .variadic = true }); | ||
196 | |||
197 | create.children << resource; | ||
198 | create.children << account; | ||
199 | create.children << identity; | ||
185 | 200 | ||
186 | syntax << create; | 201 | syntax << create; |
187 | return syntax; | 202 | return syntax; |