From 50bed81038f10091d35c5719df8078612393ae95 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Nicole?= Date: Fri, 3 Aug 2018 16:59:16 +0200 Subject: Improve documentation of SinkSH Summary: - Add support for positional arguments, options, flags in the syntax tree - Add automatic generation of usage string TODO: - ~~Better document the `--reduce` option in the `list` command~~ - Get the parent command for sub-commands so we could show help for `trace on` and not just `on` - Pass the syntax to the implementation of the command so commands can easily show help on wrong usage. Also, SyntaxTree could do automatic input validation in the future, this could also help. - Even with the new documentation, some command could still be confusing. Should we add some usage examples? Reviewers: cmollekopf Reviewed By: cmollekopf Tags: #sink Differential Revision: https://phabricator.kde.org/D14547 --- sinksh/syntax_modules/sink_remove.cpp | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 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..999a889 100644 --- a/sinksh/syntax_modules/sink_remove.cpp +++ b/sinksh/syntax_modules/sink_remove.cpp @@ -37,20 +37,12 @@ namespace SinkRemove { +Syntax::List syntax(); + bool remove(const QStringList &args, State &state) { - if (args.isEmpty()) { - state.printError(QObject::tr("A type is required"), "sink_remove/02"); - return false; - } - - if (args.count() < 2) { - state.printError(QObject::tr("A resource ID is required to remove items"), "sink_remove/03"); - return false; - } - 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,14 +129,24 @@ bool identity(const QStringList &args, State &state) return true; } - Syntax::List syntax() { Syntax remove("remove", QObject::tr("Remove items in a resource"), &SinkRemove::remove); + + 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); - resource.completer = &SinkshUtils::resourceCompleter; + identity.addPositionalArgument({ .name = "id", .help = "The ID of the account to remove" }); + remove.children << resource << account << identity; return Syntax::List() << remove; -- cgit v1.2.3