Skip to content

Commit 23ca417

Browse files
committed
remove path in results by fixing the clear of options so they go back to parsing state.
1 parent 7dbed0a commit 23ca417

File tree

2 files changed

+6
-21
lines changed

2 files changed

+6
-21
lines changed

include/CLI/Option.hpp

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,10 @@ class Option : public OptionBase<Option> {
346346
operator bool() const { return !empty(); }
347347

348348
/// Clear the parsed results (mostly for testing)
349-
void clear() { results_.clear(); }
349+
void clear() {
350+
results_.clear();
351+
current_option_state_ = option_state::parsing;
352+
}
350353

351354
///@}
352355
/// @name Setting options
@@ -918,25 +921,7 @@ class Option : public OptionBase<Option> {
918921
bool retval;
919922
if(current_option_state_ >= option_state::reduced || (results_.size() == 1 && validators_.empty())) {
920923
const results_t &res = (proc_results_.empty()) ? results_ : proc_results_;
921-
if(res.empty()) {
922-
results_t res2;
923-
if(!default_str_.empty()) {
924-
//_add_results takes an rvalue only
925-
_add_result(std::string(default_str_), res2);
926-
_validate_results(res2);
927-
results_t extra;
928-
_reduce_results(extra, res2);
929-
if(!extra.empty()) {
930-
res2 = std::move(extra);
931-
}
932-
} else {
933-
res2.push_back(std::string{});
934-
}
935-
retval = detail::lexical_conversion<T, T>(res2, output);
936-
} else {
937-
// this is the main path with no allocation
938-
retval = detail::lexical_conversion<T, T>(res, output);
939-
}
924+
retval = detail::lexical_conversion<T, T>(res, output);
940925
} else {
941926
results_t res;
942927
if(results_.empty()) {

tests/AppTest.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -882,7 +882,7 @@ TEST_F(TApp, vectorDefaults) {
882882
res = app["--long"]->as<std::vector<int>>();
883883
EXPECT_EQ(res, std::vector<int>({4}));
884884

885-
opt->take_last();
885+
opt->expected(0, 1)->take_last();
886886
run();
887887

888888
EXPECT_EQ(res, std::vector<int>({4}));

0 commit comments

Comments
 (0)