diff options
author | Minijackson <minijackson@riseup.net> | 2018-08-02 10:40:35 +0200 |
---|---|---|
committer | Minijackson <minijackson@riseup.net> | 2018-08-02 10:40:35 +0200 |
commit | eb4c557efa38673eba773bda6b71a286d0c3c3b1 (patch) | |
tree | 570600682e6a21f6f5edefab880ef20f4f298e18 /sinksh/syntax_modules/sink_modify.cpp | |
parent | a24bf3db83d81d7d7677a1f0f750f208d32998a8 (diff) | |
download | sink-eb4c557efa38673eba773bda6b71a286d0c3c3b1.tar.gz sink-eb4c557efa38673eba773bda6b71a286d0c3c3b1.zip |
Add subcommand/parameter/option/flag and automatic help
Diffstat (limited to 'sinksh/syntax_modules/sink_modify.cpp')
-rw-r--r-- | sinksh/syntax_modules/sink_modify.cpp | 50 |
1 files changed, 27 insertions, 23 deletions
diff --git a/sinksh/syntax_modules/sink_modify.cpp b/sinksh/syntax_modules/sink_modify.cpp index 2579550..cd29d56 100644 --- a/sinksh/syntax_modules/sink_modify.cpp +++ b/sinksh/syntax_modules/sink_modify.cpp | |||
@@ -38,20 +38,36 @@ | |||
38 | namespace SinkModify | 38 | namespace SinkModify |
39 | { | 39 | { |
40 | 40 | ||
41 | bool modify(const QStringList &args, State &state) | 41 | bool modify(const QStringList &args, State &state); |
42 | bool resource(const QStringList &args, State &state); | ||
43 | |||
44 | Syntax::List syntax() | ||
42 | { | 45 | { |
43 | if (args.isEmpty()) { | 46 | Syntax modify("modify", QObject::tr("Modify items in a resource"), &SinkModify::modify); |
44 | state.printError(QObject::tr("A type is required"), "sink_modify/02"); | 47 | modify.addPositionalArgument({ .name = "type", .help = "The type of entity to modify (mail, event, etc.)" }); |
45 | return false; | 48 | modify.addPositionalArgument({ .name = "resourceId", .help = "The ID of the resource containing the entity" }); |
46 | } | 49 | modify.addPositionalArgument({ .name = "objectId", .help = "The ID of the entity" }); |
50 | modify.addPositionalArgument( | ||
51 | { .name = "key value", .help = "Attributes and values to modify", .required = false, .variadic = true }); | ||
47 | 52 | ||
48 | if (args.count() < 2) { | 53 | Syntax resource("resource", QObject::tr("Modify a resource"), &SinkModify::resource);//, Syntax::EventDriven); |
49 | state.printError(QObject::tr("A resource ID is required to remove items"), "sink_modify/03"); | 54 | |
50 | return false; | 55 | resource.addPositionalArgument({ .name = "id", .help = "The ID of the resource" }); |
51 | } | 56 | resource.addPositionalArgument( |
57 | { .name = "key value", .help = "Attributes and values to modify", .required = false, .variadic = true }); | ||
58 | |||
59 | resource.completer = &SinkshUtils::resourceOrTypeCompleter; | ||
60 | modify.children << resource; | ||
61 | |||
62 | return Syntax::List() << modify; | ||
63 | } | ||
52 | 64 | ||
65 | REGISTER_SYNTAX(SinkModify) | ||
66 | |||
67 | bool modify(const QStringList &args, State &state) | ||
68 | { | ||
53 | if (args.count() < 3) { | 69 | if (args.count() < 3) { |
54 | state.printError(QObject::tr("An object ID is required to remove items"), "sink_modify/03"); | 70 | state.printError(syntax()[0].usage()); |
55 | return false; | 71 | return false; |
56 | } | 72 | } |
57 | 73 | ||
@@ -81,6 +97,7 @@ bool modify(const QStringList &args, State &state) | |||
81 | bool resource(const QStringList &args, State &state) | 97 | bool resource(const QStringList &args, State &state) |
82 | { | 98 | { |
83 | if (args.isEmpty()) { | 99 | if (args.isEmpty()) { |
100 | // TODO: pass the syntax as parameter | ||
84 | state.printError(QObject::tr("A resource can not be modified without an id"), "sink_modify/01"); | 101 | state.printError(QObject::tr("A resource can not be modified without an id"), "sink_modify/01"); |
85 | } | 102 | } |
86 | 103 | ||
@@ -105,17 +122,4 @@ bool resource(const QStringList &args, State &state) | |||
105 | return true; | 122 | return true; |
106 | } | 123 | } |
107 | 124 | ||
108 | |||
109 | Syntax::List syntax() | ||
110 | { | ||
111 | Syntax modify("modify", QObject::tr("Modify items in a resource"), &SinkModify::modify); | ||
112 | Syntax resource("resource", QObject::tr("Modify a resource"), &SinkModify::resource);//, Syntax::EventDriven); | ||
113 | resource.completer = &SinkshUtils::resourceOrTypeCompleter; | ||
114 | modify.children << resource; | ||
115 | |||
116 | return Syntax::List() << modify; | ||
117 | } | ||
118 | |||
119 | REGISTER_SYNTAX(SinkModify) | ||
120 | |||
121 | } | 125 | } |