allow unknown options for api

This commit is contained in:
orignal 2017-03-29 10:51:32 -04:00
parent 8e558f0826
commit fdf11e6038
3 changed files with 15 additions and 7 deletions

View file

@ -238,18 +238,26 @@ namespace config {
; ;
} }
void ParseCmdline(int argc, char* argv[]) { void ParseCmdline(int argc, char* argv[], bool ignoreUnknown)
try { {
try
{
auto style = boost::program_options::command_line_style::unix_style auto style = boost::program_options::command_line_style::unix_style
| boost::program_options::command_line_style::allow_long_disguise; | boost::program_options::command_line_style::allow_long_disguise;
style &= ~ boost::program_options::command_line_style::allow_guessing; style &= ~ boost::program_options::command_line_style::allow_guessing;
store(parse_command_line(argc, argv, m_OptionsDesc, style), m_Options); if (ignoreUnknown)
} catch (boost::program_options::error& e) { store(command_line_parser(argc, argv).options(m_OptionsDesc).style (style).allow_unregistered().run(), m_Options);
else
store(parse_command_line(argc, argv, m_OptionsDesc, style), m_Options);
}
catch (boost::program_options::error& e)
{
std::cerr << "args: " << e.what() << std::endl; std::cerr << "args: " << e.what() << std::endl;
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
if (m_Options.count("help") || m_Options.count("h")) { if (!ignoreUnknown && (m_Options.count("help") || m_Options.count("h")))
{
std::cout << "i2pd version " << I2PD_VERSION << " (" << I2P_VERSION << ")" << std::endl; std::cout << "i2pd version " << I2PD_VERSION << " (" << I2P_VERSION << ")" << std::endl;
std::cout << m_OptionsDesc; std::cout << m_OptionsDesc;
exit(EXIT_SUCCESS); exit(EXIT_SUCCESS);

View file

@ -41,7 +41,7 @@ namespace config {
* *
* Other exceptions will be passed to higher level. * Other exceptions will be passed to higher level.
*/ */
void ParseCmdline(int argc, char* argv[]); void ParseCmdline(int argc, char* argv[], bool ignoreUnknown = false);
/** /**
* @brief Load and parse given config file * @brief Load and parse given config file

View file

@ -19,7 +19,7 @@ namespace api
void InitI2P (int argc, char* argv[], const char * appName) void InitI2P (int argc, char* argv[], const char * appName)
{ {
i2p::config::Init (); i2p::config::Init ();
i2p::config::ParseCmdline (argc, argv); i2p::config::ParseCmdline (argc, argv, true); // ignore unknown options and help
i2p::config::Finalize (); i2p::config::Finalize ();
std::string datadir; i2p::config::GetOption("datadir", datadir); std::string datadir; i2p::config::GetOption("datadir", datadir);