summaryrefslogtreecommitdiffstats
path: root/sinksh/syntax_modules/sink_modify.cpp
diff options
context:
space:
mode:
authorRémi Nicole <nicole@kolabsystems.com>2018-08-03 16:59:16 +0200
committerChristian Mollekopf <chrigi_1@fastmail.fm>2018-08-03 17:10:31 +0200
commit50bed81038f10091d35c5719df8078612393ae95 (patch)
treee4a3b634118b2b1b9fd88203902e934299deac9b /sinksh/syntax_modules/sink_modify.cpp
parentad3dc221273100ba61828f993f1d1c8a1272d665 (diff)
downloadsink-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_modify.cpp')
-rw-r--r--sinksh/syntax_modules/sink_modify.cpp27
1 files changed, 15 insertions, 12 deletions
diff --git a/sinksh/syntax_modules/sink_modify.cpp b/sinksh/syntax_modules/sink_modify.cpp
index 2579550..6cda5ab 100644
--- a/sinksh/syntax_modules/sink_modify.cpp
+++ b/sinksh/syntax_modules/sink_modify.cpp
@@ -38,20 +38,12 @@
38namespace SinkModify 38namespace SinkModify
39{ 39{
40 40
41Syntax::List syntax();
42
41bool modify(const QStringList &args, State &state) 43bool modify(const QStringList &args, State &state)
42{ 44{
43 if (args.isEmpty()) {
44 state.printError(QObject::tr("A type is required"), "sink_modify/02");
45 return false;
46 }
47
48 if (args.count() < 2) {
49 state.printError(QObject::tr("A resource ID is required to remove items"), "sink_modify/03");
50 return false;
51 }
52
53 if (args.count() < 3) { 45 if (args.count() < 3) {
54 state.printError(QObject::tr("An object ID is required to remove items"), "sink_modify/03"); 46 state.printError(syntax()[0].usage());
55 return false; 47 return false;
56 } 48 }
57 49
@@ -81,6 +73,7 @@ bool modify(const QStringList &args, State &state)
81bool resource(const QStringList &args, State &state) 73bool resource(const QStringList &args, State &state)
82{ 74{
83 if (args.isEmpty()) { 75 if (args.isEmpty()) {
76 // TODO: pass the syntax as parameter
84 state.printError(QObject::tr("A resource can not be modified without an id"), "sink_modify/01"); 77 state.printError(QObject::tr("A resource can not be modified without an id"), "sink_modify/01");
85 } 78 }
86 79
@@ -105,11 +98,21 @@ bool resource(const QStringList &args, State &state)
105 return true; 98 return true;
106} 99}
107 100
108
109Syntax::List syntax() 101Syntax::List syntax()
110{ 102{
111 Syntax modify("modify", QObject::tr("Modify items in a resource"), &SinkModify::modify); 103 Syntax modify("modify", QObject::tr("Modify items in a resource"), &SinkModify::modify);
104 modify.addPositionalArgument({ .name = "type", .help = "The type of entity to modify (mail, event, etc.)" });
105 modify.addPositionalArgument({ .name = "resourceId", .help = "The ID of the resource containing the entity" });
106 modify.addPositionalArgument({ .name = "objectId", .help = "The ID of the entity" });
107 modify.addPositionalArgument(
108 { .name = "key value", .help = "Attributes and values to modify", .required = false, .variadic = true });
109
112 Syntax resource("resource", QObject::tr("Modify a resource"), &SinkModify::resource);//, Syntax::EventDriven); 110 Syntax resource("resource", QObject::tr("Modify a resource"), &SinkModify::resource);//, Syntax::EventDriven);
111
112 resource.addPositionalArgument({ .name = "id", .help = "The ID of the resource" });
113 resource.addPositionalArgument(
114 { .name = "key value", .help = "Attributes and values to modify", .required = false, .variadic = true });
115
113 resource.completer = &SinkshUtils::resourceOrTypeCompleter; 116 resource.completer = &SinkshUtils::resourceOrTypeCompleter;
114 modify.children << resource; 117 modify.children << resource;
115 118