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_remove.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_remove.cpp')
-rw-r--r-- | sinksh/syntax_modules/sink_remove.cpp | 55 |
1 files changed, 30 insertions, 25 deletions
diff --git a/sinksh/syntax_modules/sink_remove.cpp b/sinksh/syntax_modules/sink_remove.cpp index 6baa60f..f948290 100644 --- a/sinksh/syntax_modules/sink_remove.cpp +++ b/sinksh/syntax_modules/sink_remove.cpp | |||
@@ -37,20 +37,40 @@ | |||
37 | namespace SinkRemove | 37 | namespace SinkRemove |
38 | { | 38 | { |
39 | 39 | ||
40 | bool remove(const QStringList &args, State &state) | 40 | bool remove(const QStringList &args, State &state); |
41 | bool resource(const QStringList &args, State &state); | ||
42 | bool account(const QStringList &args, State &state); | ||
43 | bool identity(const QStringList &args, State &state); | ||
44 | |||
45 | Syntax::List syntax() | ||
41 | { | 46 | { |
42 | if (args.isEmpty()) { | 47 | Syntax remove("remove", QObject::tr("Remove items in a resource"), &SinkRemove::remove); |
43 | state.printError(QObject::tr("A type is required"), "sink_remove/02"); | ||
44 | return false; | ||
45 | } | ||
46 | 48 | ||
47 | if (args.count() < 2) { | 49 | remove.addPositionalArgument({ .name = "type", .help = "The type of entity to remove (mail, event, etc.)" }); |
48 | state.printError(QObject::tr("A resource ID is required to remove items"), "sink_remove/03"); | 50 | remove.addPositionalArgument({ .name = "resourceId", .help = "The ID of the resource containing the entity" }); |
49 | return false; | 51 | remove.addPositionalArgument({ .name = "objectId", .help = "The ID of the entity to remove" }); |
50 | } | 52 | |
53 | Syntax resource("resource", QObject::tr("Removes a resource"), &SinkRemove::resource, Syntax::NotInteractive); | ||
54 | resource.addPositionalArgument({ .name = "id", .help = "The ID of the resource to remove" }); | ||
55 | resource.completer = &SinkshUtils::resourceCompleter; | ||
56 | |||
57 | Syntax account("account", QObject::tr("Removes a account"), &SinkRemove::account, Syntax::NotInteractive); | ||
58 | account.addPositionalArgument({ .name = "id", .help = "The ID of the account to remove" }); | ||
59 | |||
60 | Syntax identity("identity", QObject::tr("Removes an identity"), &SinkRemove::identity, Syntax::NotInteractive); | ||
61 | identity.addPositionalArgument({ .name = "id", .help = "The ID of the account to remove" }); | ||
62 | |||
63 | remove.children << resource << account << identity; | ||
64 | |||
65 | return Syntax::List() << remove; | ||
66 | } | ||
67 | |||
68 | REGISTER_SYNTAX(SinkRemove) | ||
51 | 69 | ||
70 | bool remove(const QStringList &args, State &state) | ||
71 | { | ||
52 | if (args.count() < 3) { | 72 | if (args.count() < 3) { |
53 | state.printError(QObject::tr("An object ID is required to remove items"), "sink_remove/03"); | 73 | state.printError(syntax()[0].usage()); |
54 | return false; | 74 | return false; |
55 | } | 75 | } |
56 | 76 | ||
@@ -137,19 +157,4 @@ bool identity(const QStringList &args, State &state) | |||
137 | return true; | 157 | return true; |
138 | } | 158 | } |
139 | 159 | ||
140 | |||
141 | Syntax::List syntax() | ||
142 | { | ||
143 | Syntax remove("remove", QObject::tr("Remove items in a resource"), &SinkRemove::remove); | ||
144 | Syntax resource("resource", QObject::tr("Removes a resource"), &SinkRemove::resource, Syntax::NotInteractive); | ||
145 | Syntax account("account", QObject::tr("Removes a account"), &SinkRemove::account, Syntax::NotInteractive); | ||
146 | Syntax identity("identity", QObject::tr("Removes an identity"), &SinkRemove::identity, Syntax::NotInteractive); | ||
147 | resource.completer = &SinkshUtils::resourceCompleter; | ||
148 | remove.children << resource << account << identity; | ||
149 | |||
150 | return Syntax::List() << remove; | ||
151 | } | ||
152 | |||
153 | REGISTER_SYNTAX(SinkRemove) | ||
154 | |||
155 | } | 160 | } |