mirror of
https://github.com/Icinga/icinga2.git
synced 2025-07-27 15:44:11 +02:00
parent
4c8d0b9283
commit
50a1b243ed
@ -116,15 +116,20 @@ int Main(void)
|
|||||||
|
|
||||||
Utility::LoadExtensionLibrary("cli");
|
Utility::LoadExtensionLibrary("cli");
|
||||||
|
|
||||||
po::options_description desc("Global options");
|
po::options_description visibleDesc("Global options");
|
||||||
|
|
||||||
desc.add_options()
|
visibleDesc.add_options()
|
||||||
("help", "show this help message")
|
("help", "show this help message")
|
||||||
("version,V", "show version information")
|
("version,V", "show version information")
|
||||||
("define,D", po::value<std::vector<std::string> >(), "define a constant")
|
("define,D", po::value<std::vector<std::string> >(), "define a constant")
|
||||||
("library,l", po::value<std::vector<std::string> >(), "load a library")
|
("library,l", po::value<std::vector<std::string> >(), "load a library")
|
||||||
("include,I", po::value<std::vector<std::string> >(), "add include search directory")
|
("include,I", po::value<std::vector<std::string> >(), "add include search directory")
|
||||||
("log-level,x", po::value<std::string>(), "specify the log level for the console log")
|
("log-level,x", po::value<std::string>(), "specify the log level for the console log");
|
||||||
|
|
||||||
|
|
||||||
|
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");
|
||||||
|
|
||||||
String cmdname;
|
String cmdname;
|
||||||
@ -132,7 +137,7 @@ int Main(void)
|
|||||||
po::variables_map vm;
|
po::variables_map vm;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
CLICommand::ParseCommand(argc, argv, desc, vm, cmdname, command, autocomplete);
|
CLICommand::ParseCommand(argc, argv, visibleDesc, hiddenDesc, vm, cmdname, command, autocomplete);
|
||||||
} catch (const std::exception& ex) {
|
} catch (const std::exception& ex) {
|
||||||
std::ostringstream msgbuf;
|
std::ostringstream msgbuf;
|
||||||
msgbuf << "Error while parsing command-line options: " << ex.what();
|
msgbuf << "Error while parsing command-line options: " << ex.what();
|
||||||
@ -243,7 +248,7 @@ int Main(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::cout << std::endl
|
std::cout << std::endl
|
||||||
<< desc << std::endl
|
<< visibleDesc << std::endl
|
||||||
<< "Report bugs at <https://dev.icinga.org/>" << std::endl
|
<< "Report bugs at <https://dev.icinga.org/>" << std::endl
|
||||||
<< "Icinga home page: <http://www.icinga.org/>" << std::endl;
|
<< "Icinga home page: <http://www.icinga.org/>" << std::endl;
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
@ -253,7 +258,7 @@ int Main(void)
|
|||||||
int rc = 1;
|
int rc = 1;
|
||||||
|
|
||||||
if (autocomplete) {
|
if (autocomplete) {
|
||||||
CLICommand::ShowCommands(argc, argv, &desc, true, autoindex);
|
CLICommand::ShowCommands(argc, argv, &visibleDesc, &hiddenDesc, true, autoindex);
|
||||||
rc = 0;
|
rc = 0;
|
||||||
} else if (command)
|
} else if (command)
|
||||||
rc = command->Run(vm);
|
rc = command->Run(vm);
|
||||||
|
@ -63,7 +63,8 @@ RegisterCLICommandHelper::RegisterCLICommandHelper(const String& name, const CLI
|
|||||||
CLICommand::Register(vname, command);
|
CLICommand::Register(vname, command);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CLICommand::ParseCommand(int argc, char **argv, po::options_description& desc, po::variables_map& vm,
|
bool CLICommand::ParseCommand(int argc, char **argv, po::options_description& visibleDesc,
|
||||||
|
po::options_description& hiddenDesc, po::variables_map& vm,
|
||||||
String& cmdname, CLICommand::Ptr& command, bool autocomplete)
|
String& cmdname, CLICommand::Ptr& command, bool autocomplete)
|
||||||
{
|
{
|
||||||
boost::mutex::scoped_lock lock(l_RegistryMutex);
|
boost::mutex::scoped_lock lock(l_RegistryMutex);
|
||||||
@ -100,24 +101,28 @@ bool CLICommand::ParseCommand(int argc, char **argv, po::options_description& de
|
|||||||
found_command:
|
found_command:
|
||||||
lock.unlock();
|
lock.unlock();
|
||||||
|
|
||||||
po::options_description ldesc("Command options");
|
po::options_description vdesc("Command options");
|
||||||
|
|
||||||
if (command)
|
if (command)
|
||||||
command->InitParameters(ldesc);
|
command->InitParameters(vdesc, hiddenDesc);
|
||||||
|
|
||||||
desc.add(ldesc);
|
visibleDesc.add(vdesc);
|
||||||
|
|
||||||
if (autocomplete)
|
if (autocomplete)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
po::store(po::parse_command_line(argc - arg_end, argv + arg_end, desc), vm);
|
po::options_description adesc;
|
||||||
|
adesc.add(visibleDesc);
|
||||||
|
adesc.add(hiddenDesc);
|
||||||
|
|
||||||
|
po::store(po::parse_command_line(argc - arg_end, argv + arg_end, adesc), vm);
|
||||||
po::notify(vm);
|
po::notify(vm);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CLICommand::ShowCommands(int argc, char **argv, po::options_description *desc,
|
void CLICommand::ShowCommands(int argc, char **argv, po::options_description *visibleDesc,
|
||||||
bool autocomplete, int autoindex)
|
po::options_description *hiddenDesc, bool autocomplete, int autoindex)
|
||||||
{
|
{
|
||||||
boost::mutex::scoped_lock lock(l_RegistryMutex);
|
boost::mutex::scoped_lock lock(l_RegistryMutex);
|
||||||
|
|
||||||
@ -193,14 +198,14 @@ void CLICommand::ShowCommands(int argc, char **argv, po::options_description *de
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (command && autocomplete) {
|
if (command && autocomplete) {
|
||||||
po::options_description ldesc("Command options");
|
po::options_description vdesc("Command options");
|
||||||
|
|
||||||
if (command)
|
if (command)
|
||||||
command->InitParameters(ldesc);
|
command->InitParameters(vdesc, *hiddenDesc);
|
||||||
|
|
||||||
desc->add(ldesc);
|
visibleDesc->add(vdesc);
|
||||||
|
|
||||||
BOOST_FOREACH(const shared_ptr<po::option_description>& odesc, desc->options()) {
|
BOOST_FOREACH(const shared_ptr<po::option_description>& odesc, visibleDesc->options()) {
|
||||||
String cname = "--" + odesc->long_name();
|
String cname = "--" + odesc->long_name();
|
||||||
|
|
||||||
if (cname.Find(aword) == 0)
|
if (cname.Find(aword) == 0)
|
||||||
|
@ -41,16 +41,18 @@ public:
|
|||||||
|
|
||||||
virtual String GetDescription(void) const = 0;
|
virtual String GetDescription(void) const = 0;
|
||||||
virtual String GetShortDescription(void) const = 0;
|
virtual String GetShortDescription(void) const = 0;
|
||||||
virtual void InitParameters(boost::program_options::options_description& desc) const = 0;
|
virtual void InitParameters(boost::program_options::options_description& visibleDesc, boost::program_options::options_description& hiddenDesc) const = 0;
|
||||||
virtual int Run(const boost::program_options::variables_map& vm) const = 0;
|
virtual int Run(const boost::program_options::variables_map& vm) const = 0;
|
||||||
|
|
||||||
static CLICommand::Ptr GetByName(const std::vector<String>& name);
|
static CLICommand::Ptr GetByName(const std::vector<String>& name);
|
||||||
static void Register(const std::vector<String>& name, const CLICommand::Ptr& command);
|
static void Register(const std::vector<String>& name, const CLICommand::Ptr& command);
|
||||||
static void Unregister(const std::vector<String>& name);
|
static void Unregister(const std::vector<String>& name);
|
||||||
|
|
||||||
static bool ParseCommand(int argc, char **argv, boost::program_options::options_description& desc,
|
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, String& cmdname, CLICommand::Ptr& command, bool autocomplete);
|
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 *desc = NULL, bool autocomplete = false, int autoindex = -1);
|
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);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -35,7 +35,8 @@ String CAInitCommand::GetShortDescription(void) const
|
|||||||
return "sets up a new CA";
|
return "sets up a new CA";
|
||||||
}
|
}
|
||||||
|
|
||||||
void CAInitCommand::InitParameters(boost::program_options::options_description& desc) const
|
void CAInitCommand::InitParameters(boost::program_options::options_description& visibleDesc,
|
||||||
|
boost::program_options::options_description& hiddenDesc) const
|
||||||
{
|
{
|
||||||
/* Command doesn't support any parameters. */
|
/* Command doesn't support any parameters. */
|
||||||
}
|
}
|
||||||
|
@ -38,7 +38,8 @@ public:
|
|||||||
|
|
||||||
virtual String GetDescription(void) const;
|
virtual String GetDescription(void) const;
|
||||||
virtual String GetShortDescription(void) const;
|
virtual String GetShortDescription(void) const;
|
||||||
virtual void InitParameters(boost::program_options::options_description& desc) const;
|
virtual void InitParameters(boost::program_options::options_description& visibleDesc,
|
||||||
|
boost::program_options::options_description& hiddenDesc) const;
|
||||||
virtual int Run(const boost::program_options::variables_map& vm) const;
|
virtual int Run(const boost::program_options::variables_map& vm) const;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
@ -281,20 +281,25 @@ String DaemonCommand::GetShortDescription(void) const
|
|||||||
return "starts Icinga 2";
|
return "starts Icinga 2";
|
||||||
}
|
}
|
||||||
|
|
||||||
void DaemonCommand::InitParameters(boost::program_options::options_description& desc) const
|
void DaemonCommand::InitParameters(boost::program_options::options_description& visibleDesc,
|
||||||
|
boost::program_options::options_description& hiddenDesc) const
|
||||||
{
|
{
|
||||||
desc.add_options()
|
visibleDesc.add_options()
|
||||||
("config,c", po::value<std::vector<std::string> >(), "parse a configuration file")
|
("config,c", po::value<std::vector<std::string> >(), "parse a configuration file")
|
||||||
("no-config,z", "start without a configuration file")
|
("no-config,z", "start without a configuration file")
|
||||||
("validate,C", "exit after validating the configuration")
|
("validate,C", "exit after validating the configuration")
|
||||||
("errorlog,e", po::value<std::string>(), "log fatal errors to the specified log file (only works in combination with --daemonize)")
|
("errorlog,e", po::value<std::string>(), "log fatal errors to the specified log file (only works in combination with --daemonize)")
|
||||||
#ifndef _WIN32
|
#ifndef _WIN32
|
||||||
("reload-internal", po::value<int>(), "used internally to implement config reload: do not call manually, send SIGHUP instead")
|
|
||||||
("daemonize,d", "detach from the controlling terminal")
|
("daemonize,d", "detach from the controlling terminal")
|
||||||
("user,u", po::value<std::string>(), "user to run Icinga as")
|
("user,u", po::value<std::string>(), "user to run Icinga as")
|
||||||
("group,g", po::value<std::string>(), "group to run Icinga as")
|
("group,g", po::value<std::string>(), "group to run Icinga as")
|
||||||
#endif /* _WIN32 */
|
#endif /* _WIN32 */
|
||||||
;
|
;
|
||||||
|
|
||||||
|
#ifndef _WIN32
|
||||||
|
hiddenDesc.add_options()
|
||||||
|
("reload-internal", po::value<int>(), "used internally to implement config reload: do not call manually, send SIGHUP instead");
|
||||||
|
#endif /* _WIN32 */
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -39,7 +39,8 @@ public:
|
|||||||
|
|
||||||
virtual String GetDescription(void) const;
|
virtual String GetDescription(void) const;
|
||||||
virtual String GetShortDescription(void) const;
|
virtual String GetShortDescription(void) const;
|
||||||
virtual void InitParameters(boost::program_options::options_description& desc) const;
|
virtual void InitParameters(boost::program_options::options_description& visibleDesc,
|
||||||
|
boost::program_options::options_description& hiddenDesc) const;
|
||||||
virtual int Run(const boost::program_options::variables_map& vm) const;
|
virtual int Run(const boost::program_options::variables_map& vm) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user