diff options
Diffstat (limited to 'sinksh/syntax_modules/sink_create.cpp')
-rw-r--r-- | sinksh/syntax_modules/sink_create.cpp | 62 |
1 files changed, 40 insertions, 22 deletions
diff --git a/sinksh/syntax_modules/sink_create.cpp b/sinksh/syntax_modules/sink_create.cpp index f18a990..b7025cc 100644 --- a/sinksh/syntax_modules/sink_create.cpp +++ b/sinksh/syntax_modules/sink_create.cpp | |||
@@ -40,15 +40,49 @@ using namespace Sink; | |||
40 | namespace SinkCreate | 40 | namespace SinkCreate |
41 | { | 41 | { |
42 | 42 | ||
43 | bool create(const QStringList &allArgs, State &state) | 43 | bool create(const QStringList &allArgs, State &state); |
44 | bool resource(const QStringList &args, State &state); | ||
45 | bool account(const QStringList &args, State &state); | ||
46 | bool identity(const QStringList &args, State &state); | ||
47 | |||
48 | Syntax::List syntax() | ||
44 | { | 49 | { |
45 | if (allArgs.isEmpty()) { | 50 | Syntax::List syntax; |
46 | state.printError(QObject::tr("A type is required"), "sinkcreate/02"); | 51 | |
47 | return false; | 52 | Syntax create("create", QObject::tr("Create items in a resource"), &SinkCreate::create); |
48 | } | 53 | create.addPositionalArgument({ .name = "type", .help = "The type of entity to create (mail, event, etc.)" }); |
54 | create.addPositionalArgument({ .name = "resourceId", .help = "The ID of the resource that will contain the new entity" }); | ||
55 | create.addPositionalArgument( | ||
56 | { .name = "key value", .help = "Content of the entity", .required = false, .variadic = true }); | ||
57 | |||
58 | Syntax resource("resource", QObject::tr("Creates a new resource"), &SinkCreate::resource); | ||
59 | resource.addPositionalArgument({ .name = "type", .help = "The type of resource to create" }); | ||
60 | resource.addPositionalArgument( | ||
61 | { .name = "key value", .help = "Content of the resource", .required = false, .variadic = true }); | ||
49 | 62 | ||
63 | Syntax account("account", QObject::tr("Creates a new account"), &SinkCreate::account); | ||
64 | account.addPositionalArgument({ .name = "type", .help = "The type of account to create" }); | ||
65 | account.addPositionalArgument( | ||
66 | { .name = "key value", .help = "Content of the account", .required = false, .variadic = true }); | ||
67 | |||
68 | Syntax identity("identity", QObject::tr("Creates a new identity"), &SinkCreate::identity); | ||
69 | identity.addPositionalArgument( | ||
70 | { .name = "key value", .help = "Content of the identity", .required = false, .variadic = true }); | ||
71 | |||
72 | create.children << resource; | ||
73 | create.children << account; | ||
74 | create.children << identity; | ||
75 | |||
76 | syntax << create; | ||
77 | return syntax; | ||
78 | } | ||
79 | |||
80 | REGISTER_SYNTAX(SinkCreate) | ||
81 | |||
82 | bool create(const QStringList &allArgs, State &state) | ||
83 | { | ||
50 | if (allArgs.count() < 2) { | 84 | if (allArgs.count() < 2) { |
51 | state.printError(QObject::tr("A resource ID is required to create items"), "sinkcreate/03"); | 85 | state.printError(syntax()[0].usage()); |
52 | return false; | 86 | return false; |
53 | } | 87 | } |
54 | 88 | ||
@@ -173,20 +207,4 @@ bool identity(const QStringList &args, State &state) | |||
173 | return true; | 207 | return true; |
174 | } | 208 | } |
175 | 209 | ||
176 | |||
177 | Syntax::List syntax() | ||
178 | { | ||
179 | Syntax::List syntax; | ||
180 | |||
181 | 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); | ||
183 | create.children << Syntax("account", QObject::tr("Creates a new account"), &SinkCreate::account); | ||
184 | create.children << Syntax("identity", QObject::tr("Creates a new identity"), &SinkCreate::identity); | ||
185 | |||
186 | syntax << create; | ||
187 | return syntax; | ||
188 | } | ||
189 | |||
190 | REGISTER_SYNTAX(SinkCreate) | ||
191 | |||
192 | } | 210 | } |