13 #ifndef MLPACK_BINDINGS_CLI_PARSE_COMMAND_LINE_HPP 14 #define MLPACK_BINDINGS_CLI_PARSE_COMMAND_LINE_HPP 19 #include "third_party/CLI/CLI11.hpp" 28 PARAM_FLAG(
"verbose",
"Display informational messages and the full list of " 29 "parameters and timers at the end of execution.",
"v");
30 PARAM_FLAG(
"version",
"Display the version of mlpack.",
"V");
43 std::map<std::string, util::ParamData>& parameters =
IO::Parameters();
44 using ItType = std::map<std::string, util::ParamData>::iterator;
46 for (ItType it = parameters.begin(); it != parameters.end(); ++it)
62 app.
parse(argc, argv);
66 Log::Fatal <<
"An option is defined multiple times: " 67 << app.
exit(err) << std::endl;
71 Log::Fatal <<
"Required option --" << app.
exit(onf) <<
"!" << std::endl;
78 catch (std::exception& ex)
80 Log::Fatal <<
"Caught exception from parsing command line: " 81 << ex.what() << std::endl;
91 << util::GetVersion() <<
"." << std::endl;
107 std::string str = IO::GetParam<std::string>(
"info");
124 Log::Debug <<
"Compiled with debugging symbols." << std::endl;
133 for (std::map<std::string, util::ParamData>::const_iterator iter =
134 parameters.begin(); iter != parameters.end(); ++iter)
143 cliName =
"--" + cliName;
145 if (!app.
count(cliName))
147 Log::Fatal <<
"Required option " << cliName <<
" is undefined."
std::string tname
Type information of this parameter.
Definition: param_data.hpp:61
static bool HasParam(const std::string &identifier)
See if the specified flag was found while parsing.
Definition: io.cpp:85
static MLPACK_EXPORT util::NullOutStream Debug
MLPACK_EXPORT is required for global variables, so that they are properly exported by the Windows com...
Definition: log.hpp:79
Anything that can error in Parse.
Definition: CLI11.hpp:664
static MLPACK_EXPORT util::PrefixedOutStream Fatal
Prints fatal messages prefixed with [FATAL], then terminates the program.
Definition: log.hpp:90
Linear algebra utility functions, generally performed on matrices or vectors.
Definition: cv.hpp:1
static IO & GetSingleton()
Retrieve the singleton.
Definition: io.cpp:147
This structure holds all of the information about a single parameter, including its value (which is s...
Definition: param_data.hpp:52
bool ignoreInput
Discards input, prints nothing if true.
Definition: prefixedoutstream.hpp:119
#define PARAM_STRING_IN(ID, DESC, ALIAS, DEF)
Define a string input parameter.
Definition: param.hpp:335
Thrown when the wrong number of arguments has been received.
Definition: CLI11.hpp:770
#define PARAM_FLAG(ID, DESC, ALIAS)
Define a flag parameter.
Definition: param.hpp:189
Include all of the base components required to write mlpack methods, and the main mlpack Doxygen docu...
int exit(const Error &e, std::ostream &out=std::cout, std::ostream &err=std::cerr) const
Print a nice error message and return the exit code.
Definition: CLI11.hpp:6454
std::size_t count() const
No argument version of count counts the number of times this subcommand was passed in...
Definition: CLI11.hpp:6238
static std::map< std::string, util::ParamData > & Parameters()
Return a modifiable list of parameters that IO knows about.
Definition: io.cpp:154
void parse(int argc, const char *const *argv)
Parses the command line - throws errors.
Definition: CLI11.hpp:6362
void PrintHelp(const std::string ¶m)
Print the help for the given parameter.
Definition: print_help.cpp:23
static MLPACK_EXPORT util::PrefixedOutStream Info
Prints informational messages if –verbose is specified, prefixed with [INFO ].
Definition: log.hpp:84
static std::string ProgramName()
Get the program name as set by the BINDING_NAME() macro.
Definition: io.cpp:166
bool didParse
True, if IO was used to parse command line options.
Definition: io.hpp:322
Creates a command line program, with very few defaults.
Definition: CLI11.hpp:5213
Option * set_help_flag(std::string flag_name="", const std::string &help_description="")
Set a help flag, replace the existing one if present.
Definition: CLI11.hpp:5846
void ParseCommandLine(int argc, char **argv)
Parse the command line, setting all of the options inside of the CLI object to their appropriate give...
Definition: parse_command_line.hpp:36
Thrown when counting a non-existent option.
Definition: CLI11.hpp:854
bool required
True if this option is required.
Definition: param_data.hpp:71