mirror of https://github.com/Icinga/icinga2.git
parent
92454ca520
commit
d9f5409e8b
|
@ -137,15 +137,18 @@ int Main(void)
|
|||
po::options_description hiddenDesc("Hidden options");
|
||||
|
||||
hiddenDesc.add_options()
|
||||
("no-stack-rlimit", "used internally, do not specify manually");
|
||||
("no-stack-rlimit", "used internally, do not specify manually")
|
||||
("arg", po::value<std::vector<std::string> >(), "positional argument");
|
||||
|
||||
po::positional_options_description positionalDesc;
|
||||
positionalDesc.add("arg", -1);
|
||||
|
||||
String cmdname;
|
||||
CLICommand::Ptr command;
|
||||
po::variables_map vm;
|
||||
std::vector<std::string> ap;
|
||||
|
||||
try {
|
||||
CLICommand::ParseCommand(argc, argv, visibleDesc, hiddenDesc, vm, ap, cmdname, command, autocomplete);
|
||||
CLICommand::ParseCommand(argc, argv, visibleDesc, hiddenDesc, positionalDesc, vm, cmdname, command, autocomplete);
|
||||
} catch (const std::exception& ex) {
|
||||
std::ostringstream msgbuf;
|
||||
msgbuf << "Error while parsing command-line options: " << ex.what();
|
||||
|
@ -348,8 +351,13 @@ int Main(void)
|
|||
if (autocomplete) {
|
||||
CLICommand::ShowCommands(argc, argv, &visibleDesc, &hiddenDesc, true, autoindex);
|
||||
rc = 0;
|
||||
} else if (command)
|
||||
rc = command->Run(vm, ap);
|
||||
} else if (command) {
|
||||
std::vector<std::string> args;
|
||||
if (vm.count("arg"))
|
||||
args = vm["arg"].as<std::vector<std::string> >();
|
||||
|
||||
rc = command->Run(vm, args);
|
||||
}
|
||||
|
||||
#ifndef _DEBUG
|
||||
Application::Exit(rc);
|
||||
|
|
|
@ -64,9 +64,8 @@ RegisterCLICommandHelper::RegisterCLICommandHelper(const String& name, const CLI
|
|||
}
|
||||
|
||||
bool CLICommand::ParseCommand(int argc, char **argv, po::options_description& visibleDesc,
|
||||
po::options_description& hiddenDesc, po::variables_map& vm,
|
||||
std::vector<std::string>& ap, String& cmdname,
|
||||
CLICommand::Ptr& command, bool autocomplete)
|
||||
po::options_description& hiddenDesc, po::positional_options_description& positionalDesc, po::variables_map& vm,
|
||||
String& cmdname, CLICommand::Ptr& command, bool autocomplete)
|
||||
{
|
||||
boost::mutex::scoped_lock lock(l_RegistryMutex);
|
||||
|
||||
|
@ -116,13 +115,7 @@ found_command:
|
|||
adesc.add(visibleDesc);
|
||||
adesc.add(hiddenDesc);
|
||||
|
||||
po::parsed_options parsed = po::command_line_parser(argc - arg_end, argv + arg_end).
|
||||
options(adesc).allow_unregistered().run();
|
||||
|
||||
ap = collect_unrecognized(parsed.options,
|
||||
po::include_positional);
|
||||
|
||||
po::store(parsed, vm);
|
||||
po::store(po::command_line_parser(argc - arg_end, argv + arg_end).options(adesc).positional(positionalDesc).run(), vm);
|
||||
po::notify(vm);
|
||||
|
||||
return true;
|
||||
|
|
|
@ -49,8 +49,9 @@ public:
|
|||
static void Unregister(const std::vector<String>& name);
|
||||
|
||||
static bool ParseCommand(int argc, char **argv, boost::program_options::options_description& visibleDesc,
|
||||
boost::program_options::options_description& hiddenDesc,
|
||||
boost::program_options::variables_map& vm, std::vector<std::string>& ap, String& cmdname,
|
||||
boost::program_options::options_description& hiddenDesc,
|
||||
boost::program_options::positional_options_description& positionalDesc,
|
||||
boost::program_options::variables_map& vm, String& cmdname,
|
||||
CLICommand::Ptr& command, bool autocomplete);
|
||||
static void ShowCommands(int argc, char **argv, boost::program_options::options_description *visibleDesc = NULL,
|
||||
boost::program_options::options_description *hiddenDesc = NULL, bool autocomplete = false, int autoindex = -1);
|
||||
|
|
Loading…
Reference in New Issue