diff options
Diffstat (limited to 'sinksh/syntax_modules/sink_modify.cpp')
-rw-r--r-- | sinksh/syntax_modules/sink_modify.cpp | 27 |
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 @@ | |||
38 | namespace SinkModify | 38 | namespace SinkModify |
39 | { | 39 | { |
40 | 40 | ||
41 | Syntax::List syntax(); | ||
42 | |||
41 | bool modify(const QStringList &args, State &state) | 43 | bool 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) | |||
81 | bool resource(const QStringList &args, State &state) | 73 | bool 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 | |||
109 | Syntax::List syntax() | 101 | Syntax::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 | ||