[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [akonadi-next/feature/new_cli] akonadi2_cli/syntax_modules: help can now autocomplete what it shows 
From:       Aaron Seigo <aseigo () kde ! org>
Date:       2015-12-23 19:59:35
Message-ID: E1aBpZP-0006ka-M7 () scm ! kde ! org
[Download RAW message or body]

Git commit a9eb4e0c25ff4153a57a142d3ac28b8c5fc1a13d by Aaron Seigo.
Committed on 23/12/2015 at 19:53.
Pushed by aseigo into branch 'feature/new_cli'.

help can now autocomplete what it shows help for

M  +18   -1    akonadi2_cli/syntax_modules/core_syntax.cpp
M  +1    -0    akonadi2_cli/syntax_modules/core_syntax.h

http://commits.kde.org/akonadi-next/a9eb4e0c25ff4153a57a142d3ac28b8c5fc1a13d

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) {
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
     Syntax::List syntax();
     bool exit(const QStringList &commands, State &state);
     bool showHelp(const QStringList &commands, State &state);
+    QStringList showHelpCompleter(const QStringList &commands, const QString \
&fragment);  bool setDebugLevel(const QStringList &commands, State &state);
     bool printDebugLevel(const QStringList &commands, State &state);
 }


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic