13 #ifndef MLPACK_BINDINGS_CLI_PARSE_COMMAND_LINE_HPP 14 #define MLPACK_BINDINGS_CLI_PARSE_COMMAND_LINE_HPP 17 #include <boost/program_options.hpp> 27 PARAM_FLAG(
"verbose",
"Display informational messages and the full list of " 28 "parameters and timers at the end of execution.",
"v");
29 PARAM_FLAG(
"version",
"Display the version of mlpack.",
"V");
38 using namespace boost::program_options;
39 options_description desc;
44 typedef std::map<std::string, util::ParamData>::const_iterator IteratorType;
45 std::map<std::string, std::string> boostNameMap;
46 for (IteratorType it = parameters.begin(); it != parameters.end(); ++it)
54 std::string boostName;
57 boostNameMap[boostName] = d.
name;
66 basic_parsed_options<char> bpo(parse_command_line(argc, argv, desc));
71 for (
size_t i = 0; i < bpo.options.size(); ++i)
73 for (
size_t j = i + 1; j < bpo.options.size(); ++j)
75 if ((bpo.options[i].string_key == bpo.options[j].string_key) &&
76 (desc.find(bpo.options[i].string_key,
77 false).semantic()->max_tokens() <= 1))
80 if (bpo.options[i].value.size() == 0 &&
81 bpo.options[j].value.size() == 0)
87 bpo.options.erase(bpo.options.begin() + j);
96 Log::Fatal <<
"\"" << bpo.options[j].original_tokens[0] <<
"\" is " 97 <<
"defined multiple times." << std::endl;
105 catch (std::exception& ex)
107 Log::Fatal <<
"Caught exception from parsing command line: " << ex.what()
113 for (variables_map::iterator i = vmap.begin(); i != vmap.end(); ++i)
119 const std::string identifier = boostNameMap[i->first];
123 (
void*) &vmap[i->first].
value(), NULL);
152 std::string str = CLI::GetParam<std::string>(
"info");
169 Log::Debug <<
"Compiled with debugging symbols." << std::endl;
178 for (std::map<std::string, util::ParamData>::const_iterator iter =
179 parameters.begin(); iter != parameters.end(); ++iter)
184 const std::string boostName;
188 if (!vmap.count(boostName))
190 Log::Fatal <<
"Required option --" << boostName <<
" is undefined."
bool didParse
True, if CLI was used to parse command line options.
boost::any value
The actual value that is held.
bool wasPassed
True if the option was passed to the program.
static CLI & GetSingleton()
Retrieve the singleton.
static MLPACK_EXPORT util::NullOutStream Debug
MLPACK_EXPORT is required for global variables, so that they are properly exported by the Windows com...
bool ignoreInput
Discards input, prints nothing if true.
static std::string ProgramName()
Get the program name as set by the PROGRAM_INFO() macro.
static std::map< std::string, util::ParamData > & Parameters()
Return a modifiable list of parameters that CLI knows about.
static MLPACK_EXPORT util::PrefixedOutStream Fatal
Prints fatal messages prefixed with [FATAL], then terminates the program.
void ParseCommandLine(int argc, char **argv)
Parse the command line, setting all of the options inside of the CLI object to their appropriate give...
static MLPACK_EXPORT util::PrefixedOutStream Info
Prints informational messages if –verbose is specified, prefixed with [INFO ].
std::string GetVersion()
This will return either "mlpack x.y.z" or "mlpack master-XXXXXXX" depending on whether or not this is...
This structure holds all of the information about a single parameter, including its value (which is s...
std::string tname
Type information of this parameter.
Include all of the base components required to write mlpack methods, and the main mlpack Doxygen docu...
std::string name
Name of this parameter.
bool required
True if this option is required.
void PrintHelp(const std::string ¶m="")
Print the help for the given parameter.
PARAM_FLAG("help", "Default help info.", "h")
PARAM_STRING_IN("info", "Print help on a specific option.", "", "")
static bool HasParam(const std::string &identifier)
See if the specified flag was found while parsing.
FunctionMapType functionMap