MCPcopy Create free account
hub / github.com/Tencent/TAD_Sim / _validate

Method _validate

simcore/framework/src/cli/cli.hpp:6307–6338  ·  view source on GitHub ↗

Check the options to make sure there are no conflicts. Currently checks to see if multiple positionals exist with unlimited args and checks if the min and max options are feasible

Source from the content-addressed store, hash-verified

6305 /// Currently checks to see if multiple positionals exist with unlimited args and checks if the min and max options
6306 /// are feasible
6307 void _validate() const {
6308 // count the number of positional only args
6309 auto pcount = std::count_if(std::begin(options_), std::end(options_), [](const Option_p &opt) {
6310 return opt->get_items_expected_max() >= detail::expected_max_vector_size && !opt->nonpositional();
6311 });
6312 if (pcount > 1) {
6313 auto pcount_req = std::count_if(std::begin(options_), std::end(options_), [](const Option_p &opt) {
6314 return opt->get_items_expected_max() >= detail::expected_max_vector_size && !opt->nonpositional() &&
6315 opt->get_required();
6316 });
6317 if (pcount - pcount_req > 1) {
6318 throw InvalidError(name_);
6319 }
6320 }
6321
6322 std::size_t nameless_subs{0};
6323 for (const App_p &app : subcommands_) {
6324 app->_validate();
6325 if (app->get_name().empty()) ++nameless_subs;
6326 }
6327
6328 if (require_option_min_ > 0) {
6329 if (require_option_max_ > 0) {
6330 if (require_option_max_ < require_option_min_) {
6331 throw(InvalidError("Required min options greater than required max options", ExitCodes::InvalidError));
6332 }
6333 }
6334 if (require_option_min_ > (options_.size() + nameless_subs)) {
6335 throw(InvalidError("Required min options greater than number of available options", ExitCodes::InvalidError));
6336 }
6337 }
6338 }
6339
6340 /// configure subcommands to enable parsing through the current object
6341 /// set the correct fallthrough and prefix for nameless subcommands and manage the automatic enable or disable

Callers 1

_parse_positionalMethod · 0.45

Calls 9

beginFunction · 0.85
endFunction · 0.85
InvalidErrorClass · 0.85
nonpositionalMethod · 0.80
get_requiredMethod · 0.45
emptyMethod · 0.45
get_nameMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected