Print XML description for a command
I am trying to print a XML description of my program with all options etc. when the user provides a special "help" option, which could be for example --help xml, or --xmldesc etc.
This option should be handled similar to the --help option, so that no other options are processed when it is given by the user. And this is the first thing that I am struggling with. Any hint how to achieve it?
The second thing is, how would I produce the XML description? I tried the following simple approach but I need to handle flags differently for example (I did not find a way to distinguish between flags and other options):
std::string xml_description(CLI::App* command) {
std::stringstream result;
for (const auto &option : command->get_options()) {
result << R"(<option name=")" << option->get_name() << R"(" description=")" << option->get_description()
<< R"(" type=")";
if (/*option is a flag*/) {
result << "flag";
} else {
result << "option";
}
result << R"("/>)";
}
return result.str();
}
Any ideas?
Unless you are doing some complicated stuff the way to discriminate them is to use the get_expected_min() function on the option. That will be 0 for flags. It will be 1 or greater for options with required arguments.
This works very well thank you!