Hide some of the internal command-line arguments

refs #7246
This commit is contained in:
Gunnar Beutner 2014-10-10 11:08:24 +02:00
parent 4c8d0b9283
commit 50a1b243ed
7 changed files with 47 additions and 27 deletions

View File

@ -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<std::vector<std::string> >(), "define a constant")
("library,l", po::value<std::vector<std::string> >(), "load a library")
("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");
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 <https://dev.icinga.org/>" << std::endl
<< "Icinga home page: <http://www.icinga.org/>" << 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);

View File

@ -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<po::option_description>& odesc, desc->options()) {
BOOST_FOREACH(const shared_ptr<po::option_description>& odesc, visibleDesc->options()) {
String cname = "--" + odesc->long_name();
if (cname.Find(aword) == 0)

View File

@ -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<String>& name);
static void Register(const std::vector<String>& name, const CLICommand::Ptr& command);
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);
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);
};
/**

View File

@ -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. */
}

View File

@ -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;
};

View File

@ -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<std::vector<std::string> >(), "parse a configuration file")
("no-config,z", "start without a configuration file")
("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)")
#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")
("user,u", po::value<std::string>(), "user to run Icinga as")
("group,g", po::value<std::string>(), "group to run Icinga as")
#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 */
}
/**

View File

@ -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;
};