mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-01-24 22:44:15 +00:00
allow unknown options for api
This commit is contained in:
parent
8e558f0826
commit
fdf11e6038
16
Config.cpp
16
Config.cpp
@ -238,18 +238,26 @@ namespace config {
|
||||
;
|
||||
}
|
||||
|
||||
void ParseCmdline(int argc, char* argv[]) {
|
||||
try {
|
||||
void ParseCmdline(int argc, char* argv[], bool ignoreUnknown)
|
||||
{
|
||||
try
|
||||
{
|
||||
auto style = boost::program_options::command_line_style::unix_style
|
||||
| boost::program_options::command_line_style::allow_long_disguise;
|
||||
style &= ~ boost::program_options::command_line_style::allow_guessing;
|
||||
if (ignoreUnknown)
|
||||
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) {
|
||||
}
|
||||
catch (boost::program_options::error& e)
|
||||
{
|
||||
std::cerr << "args: " << e.what() << std::endl;
|
||||
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 << m_OptionsDesc;
|
||||
exit(EXIT_SUCCESS);
|
||||
|
2
Config.h
2
Config.h
@ -41,7 +41,7 @@ namespace config {
|
||||
*
|
||||
* 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
|
||||
|
2
api.cpp
2
api.cpp
@ -19,7 +19,7 @@ namespace api
|
||||
void InitI2P (int argc, char* argv[], const char * appName)
|
||||
{
|
||||
i2p::config::Init ();
|
||||
i2p::config::ParseCmdline (argc, argv);
|
||||
i2p::config::ParseCmdline (argc, argv, true); // ignore unknown options and help
|
||||
i2p::config::Finalize ();
|
||||
|
||||
std::string datadir; i2p::config::GetOption("datadir", datadir);
|
||||
|
Loading…
x
Reference in New Issue
Block a user