From: Gunnar Beutner Date: Fri, 17 Oct 2014 11:03:01 +0000 (+0200) Subject: Implement auto-completion support for type fields X-Git-Tag: v2.2.0~354 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=8e7fd1f40d1ece27a774bf20e0e0cab0ba75de91;p=icinga2 Implement auto-completion support for type fields fixes #7401 --- diff --git a/lib/base/clicommand.cpp b/lib/base/clicommand.cpp index 3ddbac6f0..9f70967ae 100644 --- a/lib/base/clicommand.cpp +++ b/lib/base/clicommand.cpp @@ -69,6 +69,27 @@ static std::vector BashArgumentCompletionHelper(const String& type, cons return result; } +void icinga::AddTypeFields(const String& type, boost::program_options::options_description& desc) +{ + const Type *ptype = Type::GetByName(type); + + if (!ptype) + return; + + for (int i = 0; i < ptype->GetFieldCount(); i++) { + Field field = ptype->GetFieldInfo(i); + + if (strcmp(field.Name, "__name") == 0) + continue; + + if (!(field.Attributes & FAConfig)) + continue; + + desc.add_options() + (field.Name, po::value(), field.Name); + } +} + ArgumentCompletionCallback icinga::BashArgumentCompletion(const String& type) { return boost::bind(BashArgumentCompletionHelper, type, _1); diff --git a/lib/base/clicommand.hpp b/lib/base/clicommand.hpp index 77af27105..a5f4153af 100644 --- a/lib/base/clicommand.hpp +++ b/lib/base/clicommand.hpp @@ -33,6 +33,7 @@ typedef boost::function (const String&)> ArgumentCompletionC typedef std::map ArgumentCompletionDescription; I2_BASE_API ArgumentCompletionCallback BashArgumentCompletion(const String& type); +I2_BASE_API void AddTypeFields(const String& type, boost::program_options::options_description& desc); /** * A CLI command. diff --git a/lib/cli/CMakeLists.txt b/lib/cli/CMakeLists.txt index 0347ab827..b97c10df3 100644 --- a/lib/cli/CMakeLists.txt +++ b/lib/cli/CMakeLists.txt @@ -28,7 +28,7 @@ endif() add_library(cli SHARED ${cli_SOURCES}) -target_link_libraries(cli ${Boost_LIBRARIES} base config remote) +target_link_libraries(cli ${Boost_LIBRARIES} base config remote icinga) set_target_properties ( cli PROPERTIES