Implement auto-completion support for type fields

fixes #7401
This commit is contained in:
Gunnar Beutner 2014-10-17 13:03:01 +02:00
parent f13ea9e1b8
commit 8e7fd1f40d
3 changed files with 23 additions and 1 deletions

View 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);

View 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.

View 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