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
| 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_)); |
nothing calls this directly
no test coverage detected