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_modify.cpp | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) (limited to 'sinksh/syntax_modules/sink_modify.cpp') diff --git a/sinksh/syntax_modules/sink_modify.cpp b/sinksh/syntax_modules/sink_modify.cpp index 2579550..6cda5ab 100644 --- a/sinksh/syntax_modules/sink_modify.cpp +++ b/sinksh/syntax_modules/sink_modify.cpp @@ -38,20 +38,12 @@ namespace SinkModify { +Syntax::List syntax(); + bool modify(const QStringList &args, State &state) { - if (args.isEmpty()) { - state.printError(QObject::tr("A type is required"), "sink_modify/02"); - return false; - } - - if (args.count() < 2) { - state.printError(QObject::tr("A resource ID is required to remove items"), "sink_modify/03"); - return false; - } - if (args.count() < 3) { - state.printError(QObject::tr("An object ID is required to remove items"), "sink_modify/03"); + state.printError(syntax()[0].usage()); return false; } @@ -81,6 +73,7 @@ bool modify(const QStringList &args, State &state) bool resource(const QStringList &args, State &state) { if (args.isEmpty()) { + // TODO: pass the syntax as parameter state.printError(QObject::tr("A resource can not be modified without an id"), "sink_modify/01"); } @@ -105,11 +98,21 @@ bool resource(const QStringList &args, State &state) return true; } - Syntax::List syntax() { Syntax modify("modify", QObject::tr("Modify items in a resource"), &SinkModify::modify); + modify.addPositionalArgument({ .name = "type", .help = "The type of entity to modify (mail, event, etc.)" }); + modify.addPositionalArgument({ .name = "resourceId", .help = "The ID of the resource containing the entity" }); + modify.addPositionalArgument({ .name = "objectId", .help = "The ID of the entity" }); + modify.addPositionalArgument( + { .name = "key value", .help = "Attributes and values to modify", .required = false, .variadic = true }); + Syntax resource("resource", QObject::tr("Modify a resource"), &SinkModify::resource);//, Syntax::EventDriven); + + resource.addPositionalArgument({ .name = "id", .help = "The ID of the resource" }); + resource.addPositionalArgument( + { .name = "key value", .help = "Attributes and values to modify", .required = false, .variadic = true }); + resource.completer = &SinkshUtils::resourceOrTypeCompleter; modify.children << resource; -- cgit v1.2.3