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

Method _parse_positional

simcore/framework/src/cli/cli.hpp:6887–6983  ·  view source on GitHub ↗

Parse a positional, go up the tree to check @param haltOnSubcommand if set to true the operation will not process subcommands merely return false Return true if the positional was used false otherwise

Source from the content-addressed store, hash-verified

6885 /// @param haltOnSubcommand if set to true the operation will not process subcommands merely return false
6886 /// Return true if the positional was used false otherwise
6887 bool _parse_positional(std::vector<std::string> &args, bool haltOnSubcommand) {
6888 const std::string &positional = args.back();
6889
6890 if (positionals_at_end_) {
6891 // deal with the case of required arguments at the end which should take precedence over other arguments
6892 auto arg_rem = args.size();
6893 auto remreq = _count_remaining_positionals(true);
6894 if (arg_rem <= remreq) {
6895 for (const Option_p &opt : options_) {
6896 if (opt->get_positional() && opt->required_) {
6897 if (static_cast<int>(opt->count()) < opt->get_items_expected_min()) {
6898 if (validate_positionals_) {
6899 std::string pos = positional;
6900 pos = opt->_validate(pos, 0);
6901 if (!pos.empty()) {
6902 continue;
6903 }
6904 }
6905 opt->add_result(positional);
6906 parse_order_.push_back(opt.get());
6907 args.pop_back();
6908 return true;
6909 }
6910 }
6911 }
6912 }
6913 }
6914 for (const Option_p &opt : options_) {
6915 // Eat options, one by one, until done
6916 if (opt->get_positional() &&
6917 (static_cast<int>(opt->count()) < opt->get_items_expected_min() || opt->get_allow_extra_args())) {
6918 if (validate_positionals_) {
6919 std::string pos = positional;
6920 pos = opt->_validate(pos, 0);
6921 if (!pos.empty()) {
6922 continue;
6923 }
6924 }
6925 opt->add_result(positional);
6926 parse_order_.push_back(opt.get());
6927 args.pop_back();
6928 return true;
6929 }
6930 }
6931
6932 for (auto &subc : subcommands_) {
6933 if ((subc->name_.empty()) && (!subc->disabled_)) {
6934 if (subc->_parse_positional(args, false)) {
6935 if (!subc->pre_parse_called_) {
6936 subc->_trigger_pre_parse(args.size());
6937 }
6938 return true;
6939 }
6940 }
6941 }
6942 // let the parent deal with it if possible
6943 if (parent_ != nullptr && fallthrough_)
6944 return _get_fallthrough_parent()->_parse_positional(args, static_cast<bool>(parse_complete_callback_));

Callers

nothing calls this directly

Calls 15

ExtrasErrorClass · 0.85
backMethod · 0.80
get_positionalMethod · 0.80
add_resultMethod · 0.80
get_allow_extra_argsMethod · 0.80
_trigger_pre_parseMethod · 0.80
_parseMethod · 0.80
_find_subcommandMethod · 0.80
sizeMethod · 0.45
countMethod · 0.45
_validateMethod · 0.45

Tested by

no test coverage detected