summaryrefslogtreecommitdiffstats
path: root/sinksh/syntaxtree.h
diff options
context:
space:
mode:
authorRémi Nicole <nicole@kolabsystems.com>2018-08-03 16:59:16 +0200
committerChristian Mollekopf <chrigi_1@fastmail.fm>2018-08-03 17:10:31 +0200
commit50bed81038f10091d35c5719df8078612393ae95 (patch)
treee4a3b634118b2b1b9fd88203902e934299deac9b /sinksh/syntaxtree.h
parentad3dc221273100ba61828f993f1d1c8a1272d665 (diff)
downloadsink-50bed81038f10091d35c5719df8078612393ae95.tar.gz
sink-50bed81038f10091d35c5719df8078612393ae95.zip
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
Diffstat (limited to 'sinksh/syntaxtree.h')
-rw-r--r--sinksh/syntaxtree.h23
1 files changed, 23 insertions, 0 deletions
diff --git a/sinksh/syntaxtree.h b/sinksh/syntaxtree.h
index ce28548..3d90288 100644
--- a/sinksh/syntaxtree.h
+++ b/sinksh/syntaxtree.h
@@ -42,10 +42,33 @@ public:
42 Syntax(const QString &keyword, const QString &helpText = QString(), 42 Syntax(const QString &keyword, const QString &helpText = QString(),
43 std::function<bool(const QStringList &, State &)> lambda = std::function<bool(const QStringList &, State &)>(), Interactivity interactivity = NotInteractive); 43 std::function<bool(const QStringList &, State &)> lambda = std::function<bool(const QStringList &, State &)>(), Interactivity interactivity = NotInteractive);
44 44
45 struct Argument {
46 QString name;
47 QString help;
48 bool required = true;
49 bool variadic = false;
50 };
51
52 struct ParameterOptions {
53 QString name;
54 QString help;
55 bool required = false;
56 };
57
58 // TODO: add examples?
45 QString keyword; 59 QString keyword;
46 QString help; 60 QString help;
61 QVector<Argument> arguments;
62 QMap<QString, ParameterOptions> parameters;
63 QMap<QString, QString> flags;
47 Interactivity interactivity; 64 Interactivity interactivity;
48 65
66 void addPositionalArgument(const Argument &);
67 void addParameter(const QString &name, const ParameterOptions &options);
68 void addFlag(const QString &name, const QString &help);
69
70 QString usage() const;
71
49 /** 72 /**
50 * This function will be called to execute the command. 73 * This function will be called to execute the command.
51 * 74 *