diff --git a/icinga-app/icinga.cpp b/icinga-app/icinga.cpp index bc46a8be4..74b965018 100644 --- a/icinga-app/icinga.cpp +++ b/icinga-app/icinga.cpp @@ -116,15 +116,20 @@ int Main(void) 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") ("version,V", "show version information") ("define,D", po::value >(), "define a constant") ("library,l", po::value >(), "load a library") ("include,I", po::value >(), "add include search directory") - ("log-level,x", po::value(), "specify the log level for the console log") + ("log-level,x", po::value(), "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"); String cmdname; @@ -132,7 +137,7 @@ int Main(void) po::variables_map vm; 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) { std::ostringstream msgbuf; msgbuf << "Error while parsing command-line options: " << ex.what(); @@ -243,7 +248,7 @@ int Main(void) } std::cout << std::endl - << desc << std::endl + << visibleDesc << std::endl << "Report bugs at " << std::endl << "Icinga home page: " << std::endl; return EXIT_SUCCESS; @@ -253,7 +258,7 @@ int Main(void) int rc = 1; if (autocomplete) { - CLICommand::ShowCommands(argc, argv, &desc, true, autoindex); + CLICommand::ShowCommands(argc, argv, &visibleDesc, &hiddenDesc, true, autoindex); rc = 0; } else if (command) rc = command->Run(vm); diff --git a/lib/base/clicommand.cpp b/lib/base/clicommand.cpp index 3856ac36a..ea227baec 100644 --- a/lib/base/clicommand.cpp +++ b/lib/base/clicommand.cpp @@ -63,7 +63,8 @@ RegisterCLICommandHelper::RegisterCLICommandHelper(const String& name, const CLI 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) { boost::mutex::scoped_lock lock(l_RegistryMutex); @@ -100,24 +101,28 @@ bool CLICommand::ParseCommand(int argc, char **argv, po::options_description& de found_command: lock.unlock(); - po::options_description ldesc("Command options"); + po::options_description vdesc("Command options"); if (command) - command->InitParameters(ldesc); + command->InitParameters(vdesc, hiddenDesc); - desc.add(ldesc); + visibleDesc.add(vdesc); if (autocomplete) 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); return true; } -void CLICommand::ShowCommands(int argc, char **argv, po::options_description *desc, - bool autocomplete, int autoindex) +void CLICommand::ShowCommands(int argc, char **argv, po::options_description *visibleDesc, + po::options_description *hiddenDesc, bool autocomplete, int autoindex) { 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) { - po::options_description ldesc("Command options"); + po::options_description vdesc("Command options"); - if (command) - command->InitParameters(ldesc); + if (command) + command->InitParameters(vdesc, *hiddenDesc); - desc->add(ldesc); + visibleDesc->add(vdesc); - BOOST_FOREACH(const shared_ptr& odesc, desc->options()) { + BOOST_FOREACH(const shared_ptr& odesc, visibleDesc->options()) { String cname = "--" + odesc->long_name(); if (cname.Find(aword) == 0) diff --git a/lib/base/clicommand.hpp b/lib/base/clicommand.hpp index b2f52dd7c..fd3443b4c 100644 --- a/lib/base/clicommand.hpp +++ b/lib/base/clicommand.hpp @@ -41,16 +41,18 @@ public: virtual String GetDescription(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; static CLICommand::Ptr GetByName(const std::vector& name); static void Register(const std::vector& name, const CLICommand::Ptr& command); static void Unregister(const std::vector& 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); - 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); }; /** diff --git a/lib/cli/cainitcommand.cpp b/lib/cli/cainitcommand.cpp index 947e16397..01bc054d1 100644 --- a/lib/cli/cainitcommand.cpp +++ b/lib/cli/cainitcommand.cpp @@ -35,7 +35,8 @@ String CAInitCommand::GetShortDescription(void) const 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. */ } diff --git a/lib/cli/cainitcommand.hpp b/lib/cli/cainitcommand.hpp index 5723b7254..7dabbc86c 100644 --- a/lib/cli/cainitcommand.hpp +++ b/lib/cli/cainitcommand.hpp @@ -38,7 +38,8 @@ public: virtual String GetDescription(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; }; diff --git a/lib/cli/daemoncommand.cpp b/lib/cli/daemoncommand.cpp index 5acd2e212..da6000197 100644 --- a/lib/cli/daemoncommand.cpp +++ b/lib/cli/daemoncommand.cpp @@ -281,20 +281,25 @@ String DaemonCommand::GetShortDescription(void) const 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 >(), "parse a configuration file") ("no-config,z", "start without a configuration file") ("validate,C", "exit after validating the configuration") ("errorlog,e", po::value(), "log fatal errors to the specified log file (only works in combination with --daemonize)") #ifndef _WIN32 - ("reload-internal", po::value(), "used internally to implement config reload: do not call manually, send SIGHUP instead") ("daemonize,d", "detach from the controlling terminal") ("user,u", po::value(), "user to run Icinga as") ("group,g", po::value(), "group to run Icinga as") #endif /* _WIN32 */ ; + +#ifndef _WIN32 + hiddenDesc.add_options() + ("reload-internal", po::value(), "used internally to implement config reload: do not call manually, send SIGHUP instead"); +#endif /* _WIN32 */ } /** diff --git a/lib/cli/daemoncommand.hpp b/lib/cli/daemoncommand.hpp index 6dee2fc0c..713587fd0 100644 --- a/lib/cli/daemoncommand.hpp +++ b/lib/cli/daemoncommand.hpp @@ -39,7 +39,8 @@ public: virtual String GetDescription(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; };