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_create.cpp | 62 ++++++++++++++++++++++------------- 1 file changed, 40 insertions(+), 22 deletions(-) (limited to 'sinksh/syntax_modules/sink_create.cpp') 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; namespace SinkCreate { -bool create(const QStringList &allArgs, State &state) +bool create(const QStringList &allArgs, 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 (allArgs.isEmpty()) { - state.printError(QObject::tr("A type is required"), "sinkcreate/02"); - return false; - } + Syntax::List syntax; + + Syntax create("create", QObject::tr("Create items in a resource"), &SinkCreate::create); + create.addPositionalArgument({ .name = "type", .help = "The type of entity to create (mail, event, etc.)" }); + create.addPositionalArgument({ .name = "resourceId", .help = "The ID of the resource that will contain the new entity" }); + create.addPositionalArgument( + { .name = "key value", .help = "Content of the entity", .required = false, .variadic = true }); + + Syntax resource("resource", QObject::tr("Creates a new resource"), &SinkCreate::resource); + resource.addPositionalArgument({ .name = "type", .help = "The type of resource to create" }); + resource.addPositionalArgument( + { .name = "key value", .help = "Content of the resource", .required = false, .variadic = true }); + Syntax account("account", QObject::tr("Creates a new account"), &SinkCreate::account); + account.addPositionalArgument({ .name = "type", .help = "The type of account to create" }); + account.addPositionalArgument( + { .name = "key value", .help = "Content of the account", .required = false, .variadic = true }); + + Syntax identity("identity", QObject::tr("Creates a new identity"), &SinkCreate::identity); + identity.addPositionalArgument( + { .name = "key value", .help = "Content of the identity", .required = false, .variadic = true }); + + create.children << resource; + create.children << account; + create.children << identity; + + syntax << create; + return syntax; +} + +REGISTER_SYNTAX(SinkCreate) + +bool create(const QStringList &allArgs, State &state) +{ if (allArgs.count() < 2) { - state.printError(QObject::tr("A resource ID is required to create items"), "sinkcreate/03"); + state.printError(syntax()[0].usage()); return false; } @@ -173,20 +207,4 @@ bool identity(const QStringList &args, State &state) return true; } - -Syntax::List syntax() -{ - Syntax::List syntax; - - Syntax create("create", QObject::tr("Create items in a resource"), &SinkCreate::create); - create.children << Syntax("resource", QObject::tr("Creates a new resource"), &SinkCreate::resource); - create.children << Syntax("account", QObject::tr("Creates a new account"), &SinkCreate::account); - create.children << Syntax("identity", QObject::tr("Creates a new identity"), &SinkCreate::identity); - - syntax << create; - return syntax; -} - -REGISTER_SYNTAX(SinkCreate) - } -- cgit v1.2.3