From a2b701ad44521988c5cc93f0db01d4d1b268e2ab Mon Sep 17 00:00:00 2001 From: Gunnar Beutner Date: Wed, 18 Mar 2015 08:10:32 +0100 Subject: [PATCH] Improve auto-completion for the 'icinga2 console' command refs #8776 --- lib/cli/consolecommand.cpp | 36 ++++++++++++++++++++++++++++++++++++ lib/cli/editline.hpp | 1 + 2 files changed, 37 insertions(+) diff --git a/lib/cli/consolecommand.cpp b/lib/cli/consolecommand.cpp index cd8389a81..a8d509e7c 100644 --- a/lib/cli/consolecommand.cpp +++ b/lib/cli/consolecommand.cpp @@ -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::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(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