mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-02-08 22:13:48 +01:00
allow unknown options for api
This commit is contained in:
parent
8e558f0826
commit
fdf11e6038
3 changed files with 15 additions and 7 deletions
18
Config.cpp
18
Config.cpp
|
@ -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);
|
||||||
|
|
2
Config.h
2
Config.h
|
@ -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
|
||||||
|
|
2
api.cpp
2
api.cpp
|
@ -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);
|
||||||
|
|
Loading…
Add table
Reference in a new issue