From a9eb4e0c25ff4153a57a142d3ac28b8c5fc1a13d Mon Sep 17 00:00:00 2001 From: Aaron Seigo Date: Wed, 23 Dec 2015 20:53:41 +0100 Subject: help can now autocomplete what it shows help for --- akonadi2_cli/syntax_modules/core_syntax.cpp | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) (limited to 'akonadi2_cli/syntax_modules/core_syntax.cpp') 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() { Syntax::List syntax; syntax << Syntax("exit", QObject::tr("Exits the application. Ctrl-d also works!"), &CoreSyntax::exit); - syntax << Syntax(QObject::tr("help"), QObject::tr("Print command information: help [command]"), &CoreSyntax::showHelp); + + Syntax help(QObject::tr("help"), QObject::tr("Print command information: help [command]"), &CoreSyntax::showHelp); + help.completer = &CoreSyntax::showHelpCompleter; + syntax << help; Syntax set(QObject::tr("set"), QObject::tr("Sets settings for the session")); 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) return true; } +QStringList showHelpCompleter(const QStringList &commands, const QString &fragment) +{ + QStringList items; + + for (auto syntax: SyntaxTree::self()->syntax()) { + if (fragment.isEmpty() || syntax.keyword.startsWith(fragment)) { + items << syntax.keyword; + } + } + + qSort(items); + return items; +} + bool setDebugLevel(const QStringList &commands, State &state) { if (commands.count() != 1) { -- cgit v1.2.3