@@ -695,8 +695,8 @@ parse_result::count(const std::string& o) const {
695
695
}
696
696
697
697
bool
698
- parse_result::has (const std::string& o ) const {
699
- return count (o ) != 0 ;
698
+ parse_result::has (const std::string& opt ) const {
699
+ return count (opt ) != 0 ;
700
700
}
701
701
702
702
const option_value&
@@ -859,25 +859,29 @@ class options::option_parser {
859
859
++current;
860
860
}
861
861
862
+ // Setup default or env values.
862
863
for (auto & opt : options_) {
863
864
auto & detail = opt.second ;
864
- const auto & value = detail->value ();
865
-
866
865
auto & store = parsed_[detail->hash ()];
866
+ const auto & value = detail->value ();
867
867
868
- if (value->has_default ()) {
869
- if (!store.count () && !store.has_default ()) {
870
- parse_default (detail);
871
- }
872
- } else {
873
- parse_no_value (detail);
868
+ // Skip options with parsed values.
869
+ if (store.count () || store.has_default ()) {
870
+ continue ;
874
871
}
875
-
876
- if (value->has_env () && !store. count ()) {
872
+ // Try to setup env value.
873
+ if (value->has_env ()) {
877
874
if (const char * env = std::getenv (value->get_env_var ().c_str ())) {
878
875
store.parse (detail, std::string (env));
876
+ continue ;
879
877
}
880
878
}
879
+ // Try to setup default value.
880
+ if (value->has_default ()) {
881
+ store.parse_default (detail);
882
+ } else {
883
+ store.parse_no_value (detail);
884
+ }
881
885
}
882
886
883
887
parse_result::name_hash_map keys;
0 commit comments