summaryrefslogtreecommitdiffstats
path: root/sinksh/syntax_modules/sink_modify.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'sinksh/syntax_modules/sink_modify.cpp')
-rw-r--r--sinksh/syntax_modules/sink_modify.cpp50
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 @@
38namespace SinkModify 38namespace SinkModify
39{ 39{
40 40
41bool modify(const QStringList &args, State &state) 41bool modify(const QStringList &args, State &state);
42bool resource(const QStringList &args, State &state);
43
44Syntax::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
65REGISTER_SYNTAX(SinkModify)
66
67bool 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)
81bool resource(const QStringList &args, State &state) 97bool 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
109Syntax::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
119REGISTER_SYNTAX(SinkModify)
120
121} 125}