]> granicus.if.org Git - icinga2/commitdiff
Improve auto-completion for the 'icinga2 console' command
authorGunnar Beutner <gunnar@beutner.name>
Wed, 18 Mar 2015 07:10:32 +0000 (08:10 +0100)
committerGunnar Beutner <gunnar@beutner.name>
Wed, 18 Mar 2015 07:10:32 +0000 (08:10 +0100)
refs #8776

lib/cli/consolecommand.cpp
lib/cli/editline.hpp

index cd8389a8199b68759ccfa719beb06d0e19d36827..a8d509e7c1c9ede1726a53f6fc7d9cf50aefa2e7 100644 (file)
@@ -120,6 +120,41 @@ static char *ConsoleCompleteHelper(const char *word, int state)
                                AddSuggestion(matches, word, kv.first);
                        }
                }
+
+               String::SizeType cperiod = aword.RFind(".");
+
+               if (cperiod != -1) {
+                       String pword = aword.SubStr(0, cperiod);
+
+                       Value value;
+
+                       try {
+                               Expression *expr = ConfigCompiler::CompileText("temp", pword);
+
+                               if (expr)
+                                       value = expr->Evaluate(l_ScriptFrame);
+
+                               if (value.IsObjectType<Dictionary>()) {
+                                       Dictionary::Ptr dict = value;
+
+                                       ObjectLock olock(dict);
+                                       BOOST_FOREACH(const Dictionary::Pair& kv, dict) {
+                                               AddSuggestion(matches, word, pword + "." + kv.first);
+                                       }
+                               }
+
+                               Type::Ptr type = value.GetReflectionType();
+                               Object::Ptr prototype = type->GetPrototype();
+                               Dictionary::Ptr dict = dynamic_pointer_cast<Dictionary>(prototype);
+
+                               if (dict) {
+                                       ObjectLock olock(dict);
+                                       BOOST_FOREACH(const Dictionary::Pair& kv, dict) {
+                                               AddSuggestion(matches, word, pword + "." + kv.first);
+                                       }
+                               }
+                       } catch (...) { /* Ignore the exception */ }
+               }
        }
 
        if (state >= matches.size())
@@ -141,6 +176,7 @@ int ConsoleCommand::Run(const po::variables_map& vm, const std::vector<std::stri
 
 #ifdef HAVE_EDITLINE
        rl_completion_entry_function = ConsoleCompleteHelper;
+       rl_completion_append_character = '\0';
 #endif /* HAVE_EDITLINE */
 
        String addr, session;
index 2ae7ab7b57f3707a19a96a73c839904dba51cd2e..0fbc80a6ebb3f04ef9717adef6a1d0bd8c9881ea 100644 (file)
@@ -27,6 +27,7 @@ int add_history(const char *line);
 
 typedef char *ELFunction(const char *, int);
 
+extern char rl_completion_append_character;
 extern ELFunction *rl_completion_entry_function;
 
 }