From eb4c557efa38673eba773bda6b71a286d0c3c3b1 Mon Sep 17 00:00:00 2001 From: Minijackson Date: Thu, 2 Aug 2018 10:40:35 +0200 Subject: Add subcommand/parameter/option/flag and automatic help --- sinksh/syntax_modules/sink_remove.cpp | 55 +++++++++++++++++++---------------- 1 file changed, 30 insertions(+), 25 deletions(-) (limited to 'sinksh/syntax_modules/sink_remove.cpp') 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 @@ namespace SinkRemove { -bool remove(const QStringList &args, State &state) +bool remove(const QStringList &args, State &state); +bool resource(const QStringList &args, State &state); +bool account(const QStringList &args, State &state); +bool identity(const QStringList &args, State &state); + +Syntax::List syntax() { - if (args.isEmpty()) { - state.printError(QObject::tr("A type is required"), "sink_remove/02"); - return false; - } + Syntax remove("remove", QObject::tr("Remove items in a resource"), &SinkRemove::remove); - if (args.count() < 2) { - state.printError(QObject::tr("A resource ID is required to remove items"), "sink_remove/03"); - return false; - } + remove.addPositionalArgument({ .name = "type", .help = "The type of entity to remove (mail, event, etc.)" }); + remove.addPositionalArgument({ .name = "resourceId", .help = "The ID of the resource containing the entity" }); + remove.addPositionalArgument({ .name = "objectId", .help = "The ID of the entity to remove" }); + + Syntax resource("resource", QObject::tr("Removes a resource"), &SinkRemove::resource, Syntax::NotInteractive); + resource.addPositionalArgument({ .name = "id", .help = "The ID of the resource to remove" }); + resource.completer = &SinkshUtils::resourceCompleter; + + Syntax account("account", QObject::tr("Removes a account"), &SinkRemove::account, Syntax::NotInteractive); + account.addPositionalArgument({ .name = "id", .help = "The ID of the account to remove" }); + + Syntax identity("identity", QObject::tr("Removes an identity"), &SinkRemove::identity, Syntax::NotInteractive); + identity.addPositionalArgument({ .name = "id", .help = "The ID of the account to remove" }); + + remove.children << resource << account << identity; + + return Syntax::List() << remove; +} + +REGISTER_SYNTAX(SinkRemove) +bool remove(const QStringList &args, State &state) +{ if (args.count() < 3) { - state.printError(QObject::tr("An object ID is required to remove items"), "sink_remove/03"); + state.printError(syntax()[0].usage()); return false; } @@ -137,19 +157,4 @@ bool identity(const QStringList &args, State &state) return true; } - -Syntax::List syntax() -{ - Syntax remove("remove", QObject::tr("Remove items in a resource"), &SinkRemove::remove); - Syntax resource("resource", QObject::tr("Removes a resource"), &SinkRemove::resource, Syntax::NotInteractive); - Syntax account("account", QObject::tr("Removes a account"), &SinkRemove::account, Syntax::NotInteractive); - Syntax identity("identity", QObject::tr("Removes an identity"), &SinkRemove::identity, Syntax::NotInteractive); - resource.completer = &SinkshUtils::resourceCompleter; - remove.children << resource << account << identity; - - return Syntax::List() << remove; -} - -REGISTER_SYNTAX(SinkRemove) - } -- cgit v1.2.3