@@ -82,7 +82,7 @@ CLI11_NODISCARD CLI11_INLINE char **App::ensure_utf8(char **argv) {
82
82
CLI11_INLINE App *App::name (std::string app_name) {
83
83
84
84
if (parent_ != nullptr ) {
85
- auto oname = name_;
85
+ std::string oname = name_;
86
86
name_ = app_name;
87
87
const auto &res = _compare_subcommand_names (*this , *_get_fallthrough_parent ());
88
88
if (!res.empty ()) {
@@ -832,7 +832,7 @@ CLI11_NODISCARD CLI11_INLINE bool App::check_name(std::string name_to_check) con
832
832
if (local_name == name_to_check) {
833
833
return true ;
834
834
}
835
- for (auto les : aliases_) { // NOLINT(performance-for-range-copy)
835
+ for (std::string les : aliases_) { // NOLINT(performance-for-range-copy)
836
836
if (ignore_underscore_) {
837
837
les = detail::remove_underscore (les);
838
838
}
@@ -1556,6 +1556,7 @@ CLI11_NODISCARD CLI11_INLINE bool App::_has_remaining_positionals() const {
1556
1556
CLI11_INLINE bool App::_parse_positional (std::vector<std::string> &args, bool haltOnSubcommand) {
1557
1557
1558
1558
const std::string &positional = args.back ();
1559
+ Option *posOpt{nullptr };
1559
1560
1560
1561
if (positionals_at_end_) {
1561
1562
// deal with the case of required arguments at the end which should take precedence over other arguments
@@ -1572,56 +1573,47 @@ CLI11_INLINE bool App::_parse_positional(std::vector<std::string> &args, bool ha
1572
1573
continue ;
1573
1574
}
1574
1575
}
1575
-
1576
- parse_order_.push_back (opt.get ());
1577
- // / if we require a separator add it here
1578
- if (opt->get_inject_separator ()) {
1579
- if (!opt->results ().empty () && !opt->results ().back ().empty ()) {
1580
- opt->add_result (std::string{});
1581
- }
1582
- }
1583
- if (opt->get_trigger_on_parse () &&
1584
- opt->current_option_state_ == Option::option_state::callback_run) {
1585
- opt->clear ();
1586
- }
1587
- opt->add_result (positional);
1588
- if (opt->get_trigger_on_parse ()) {
1589
- opt->run_callback ();
1590
- }
1591
- args.pop_back ();
1592
- return true ;
1576
+ posOpt = opt.get ();
1577
+ break ;
1593
1578
}
1594
1579
}
1595
1580
}
1596
1581
}
1597
1582
}
1598
- for (const Option_p &opt : options_) {
1599
- // Eat options, one by one, until done
1600
- if (opt->get_positional () &&
1601
- (static_cast <int >(opt->count ()) < opt->get_items_expected_min () || opt->get_allow_extra_args ())) {
1602
- if (validate_positionals_) {
1603
- std::string pos = positional;
1604
- pos = opt->_validate (pos, 0 );
1605
- if (!pos.empty ()) {
1606
- continue ;
1607
- }
1608
- }
1609
- if (opt->get_inject_separator ()) {
1610
- if (!opt->results ().empty () && !opt->results ().back ().empty ()) {
1611
- opt->add_result (std::string{});
1583
+ if (posOpt == nullptr ) {
1584
+ for (const Option_p &opt : options_) {
1585
+ // Eat options, one by one, until done
1586
+ if (opt->get_positional () &&
1587
+ (static_cast <int >(opt->count ()) < opt->get_items_expected_min () || opt->get_allow_extra_args ())) {
1588
+ if (validate_positionals_) {
1589
+ std::string pos = positional;
1590
+ pos = opt->_validate (pos, 0 );
1591
+ if (!pos.empty ()) {
1592
+ continue ;
1593
+ }
1612
1594
}
1595
+ posOpt = opt.get ();
1596
+ break ;
1613
1597
}
1614
- if (opt->get_trigger_on_parse () && opt->current_option_state_ == Option::option_state::callback_run) {
1615
- opt->clear ();
1616
- }
1617
- opt->add_result (positional);
1618
- if (opt->get_trigger_on_parse ()) {
1619
- opt->run_callback ();
1598
+ }
1599
+ }
1600
+ if (posOpt != nullptr ) {
1601
+ parse_order_.push_back (posOpt);
1602
+ if (posOpt->get_inject_separator ()) {
1603
+ if (!posOpt->results ().empty () && !posOpt->results ().back ().empty ()) {
1604
+ posOpt->add_result (std::string{});
1620
1605
}
1621
- parse_order_.push_back (opt.get ());
1622
- args.pop_back ();
1623
- return true ;
1624
1606
}
1607
+ if (posOpt->get_trigger_on_parse () && posOpt->current_option_state_ == Option::option_state::callback_run) {
1608
+ posOpt->clear ();
1609
+ }
1610
+ posOpt->add_result (positional);
1611
+ if (posOpt->get_trigger_on_parse ()) {
1612
+ posOpt->run_callback ();
1613
+ }
1614
+
1615
+ args.pop_back ();
1616
+ return true ;
1625
1617
}
1626
1618
1627
1619
for (auto &subc : subcommands_) {
@@ -1964,7 +1956,7 @@ CLI11_INLINE void App::_trigger_pre_parse(std::size_t remaining_args) {
1964
1956
} else if (immediate_callback_) {
1965
1957
if (!name_.empty ()) {
1966
1958
auto pcnt = parsed_;
1967
- auto extras = std::move (missing_);
1959
+ missing_t extras = std::move (missing_);
1968
1960
clear ();
1969
1961
parsed_ = pcnt;
1970
1962
pre_parse_called_ = true ;
@@ -2150,12 +2142,12 @@ CLI11_INLINE void retire_option(App *app, Option *opt) {
2150
2142
->allow_extra_args (opt->get_allow_extra_args ());
2151
2143
2152
2144
app->remove_option (opt);
2153
- auto *opt2 = app->add_option (option_copy->get_name (false , true ), " option has been retired and has no effect" )
2154
- ->type_name (" RETIRED" )
2155
- ->default_str (" RETIRED" )
2156
- ->type_size (option_copy->get_type_size_min (), option_copy->get_type_size_max ())
2157
- ->expected (option_copy->get_expected_min (), option_copy->get_expected_max ())
2158
- ->allow_extra_args (option_copy->get_allow_extra_args ());
2145
+ auto *opt2 = app->add_option (option_copy->get_name (false , true ), " option has been retired and has no effect" );
2146
+ opt2 ->type_name (" RETIRED" )
2147
+ ->default_str (" RETIRED" )
2148
+ ->type_size (option_copy->get_type_size_min (), option_copy->get_type_size_max ())
2149
+ ->expected (option_copy->get_expected_min (), option_copy->get_expected_max ())
2150
+ ->allow_extra_args (option_copy->get_allow_extra_args ());
2159
2151
2160
2152
Validator retired_warning{[opt2](std::string &) {
2161
2153
std::cout << " WARNING " << opt2->get_name () << " is retired and has no effect\n " ;
0 commit comments