]> granicus.if.org Git - icinga2/commitdiff
Implement auto-completion support for type fields
authorGunnar Beutner <gunnar@beutner.name>
Fri, 17 Oct 2014 11:03:01 +0000 (13:03 +0200)
committerGunnar Beutner <gunnar@beutner.name>
Fri, 17 Oct 2014 11:03:01 +0000 (13:03 +0200)
fixes #7401

lib/base/clicommand.cpp
lib/base/clicommand.hpp
lib/cli/CMakeLists.txt

index 3ddbac6f0ff556225e98729b67577b6f0960a3d8..9f70967ae5347e5142a2f6f77fa38018676eb8e5 100644 (file)
@@ -69,6 +69,27 @@ static std::vector<String> 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<std::string>(), field.Name);
+       }
+}
+
 ArgumentCompletionCallback icinga::BashArgumentCompletion(const String& type)
 {
        return boost::bind(BashArgumentCompletionHelper, type, _1);
index 77af27105f3f1b47fea296884b4211a783ec6ffe..a5f4153af912672e4a1209567b54f4049d4e40d4 100644 (file)
@@ -33,6 +33,7 @@ typedef boost::function<std::vector<String> (const String&)> ArgumentCompletionC
 typedef std::map<String, ArgumentCompletionCallback> 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.
index 0347ab8274b5f13132b5f22b7048112f4af133a6..b97c10df3bc53cc3f8198a3f6d8f95fc9bca8d58 100644 (file)
@@ -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