CLI11
CLI11 copied to clipboard
Subcommand require message improvement ?
Hi, if a param (ex: value) is required for a subcommand (ex: consumer) is setted has required, the error message is not always helpfull if another subcommand has the same param name. Ex:
[consumer]
;value=101
[another]
value=102
The mesage displayed will be:
--value is required
something like : --consumer.value is required will be of more help. Regards, PS: Looking quickly to the code, I not found where I can get the subcommand name (in App.hpp near line 2315, with the
throw RequiredError(opt->get_name());
Playing a little with the code...
into bool _parse_single_config(const ConfigItem &item, std::size_t level = 0) from App.hpp
adding the joined parents like this:
// check for section close
if(item.name == "--") {
if(configurable_) {
_process_callbacks();
_process_requirements(detail::join(item.parents, "."));
run_callback();
}
return true;
}
and changing void _process_requirements(const std::string& parents = "")
// Required but empty
if(opt->get_required() && opt->count() == 0) {
std::string message{"--"};
if (!parents.empty()) message += parents + ".";
throw RequiredError(message + detail::trim_copy(opt->get_name(), "-"));
}
but not sure about what is exactly parents. At least, the message is cleaner now for my case. To much other usage of process_requirements to guess all the impact.