summaryrefslogtreecommitdiffstats
path: root/akonadi2_cli/syntax_modules
diff options
context:
space:
mode:
authorAaron Seigo <aseigo@kde.org>2015-12-23 20:53:41 +0100
committerAaron Seigo <aseigo@kde.org>2015-12-23 20:53:41 +0100
commita9eb4e0c25ff4153a57a142d3ac28b8c5fc1a13d (patch)
tree97f2b5804abab68b20ae5c011551e645c99cc723 /akonadi2_cli/syntax_modules
parent42d772acc88a2c57b5761b67918ae7f502a9a7f9 (diff)
downloadsink-a9eb4e0c25ff4153a57a142d3ac28b8c5fc1a13d.tar.gz
sink-a9eb4e0c25ff4153a57a142d3ac28b8c5fc1a13d.zip
help can now autocomplete what it shows help for
Diffstat (limited to 'akonadi2_cli/syntax_modules')
-rw-r--r--akonadi2_cli/syntax_modules/core_syntax.cpp19
-rw-r--r--akonadi2_cli/syntax_modules/core_syntax.h1
2 files changed, 19 insertions, 1 deletions
diff --git a/akonadi2_cli/syntax_modules/core_syntax.cpp b/akonadi2_cli/syntax_modules/core_syntax.cpp
index 407fcbf..ca5ac4c 100644
--- a/akonadi2_cli/syntax_modules/core_syntax.cpp
+++ b/akonadi2_cli/syntax_modules/core_syntax.cpp
@@ -31,7 +31,10 @@ Syntax::List syntax()
31{ 31{
32 Syntax::List syntax; 32 Syntax::List syntax;
33 syntax << Syntax("exit", QObject::tr("Exits the application. Ctrl-d also works!"), &CoreSyntax::exit); 33 syntax << Syntax("exit", QObject::tr("Exits the application. Ctrl-d also works!"), &CoreSyntax::exit);
34 syntax << Syntax(QObject::tr("help"), QObject::tr("Print command information: help [command]"), &CoreSyntax::showHelp); 34
35 Syntax help(QObject::tr("help"), QObject::tr("Print command information: help [command]"), &CoreSyntax::showHelp);
36 help.completer = &CoreSyntax::showHelpCompleter;
37 syntax << help;
35 38
36 Syntax set(QObject::tr("set"), QObject::tr("Sets settings for the session")); 39 Syntax set(QObject::tr("set"), QObject::tr("Sets settings for the session"));
37 set.children << Syntax(QObject::tr("debug"), QObject::tr("Set the debug level from 0 to 6"), &CoreSyntax::setDebugLevel); 40 set.children << Syntax(QObject::tr("debug"), QObject::tr("Set the debug level from 0 to 6"), &CoreSyntax::setDebugLevel);
@@ -92,6 +95,20 @@ bool showHelp(const QStringList &commands, State &state)
92 return true; 95 return true;
93} 96}
94 97
98QStringList showHelpCompleter(const QStringList &commands, const QString &fragment)
99{
100 QStringList items;
101
102 for (auto syntax: SyntaxTree::self()->syntax()) {
103 if (fragment.isEmpty() || syntax.keyword.startsWith(fragment)) {
104 items << syntax.keyword;
105 }
106 }
107
108 qSort(items);
109 return items;
110}
111
95bool setDebugLevel(const QStringList &commands, State &state) 112bool setDebugLevel(const QStringList &commands, State &state)
96{ 113{
97 if (commands.count() != 1) { 114 if (commands.count() != 1) {
diff --git a/akonadi2_cli/syntax_modules/core_syntax.h b/akonadi2_cli/syntax_modules/core_syntax.h
index 521cb8e..89187e5 100644
--- a/akonadi2_cli/syntax_modules/core_syntax.h
+++ b/akonadi2_cli/syntax_modules/core_syntax.h
@@ -26,6 +26,7 @@ namespace CoreSyntax
26 Syntax::List syntax(); 26 Syntax::List syntax();
27 bool exit(const QStringList &commands, State &state); 27 bool exit(const QStringList &commands, State &state);
28 bool showHelp(const QStringList &commands, State &state); 28 bool showHelp(const QStringList &commands, State &state);
29 QStringList showHelpCompleter(const QStringList &commands, const QString &fragment);
29 bool setDebugLevel(const QStringList &commands, State &state); 30 bool setDebugLevel(const QStringList &commands, State &state);
30 bool printDebugLevel(const QStringList &commands, State &state); 31 bool printDebugLevel(const QStringList &commands, State &state);
31} 32}