| 815 | /// Set the default value and validate the results and run the callback if appropriate to set the value into the |
| 816 | /// bound value only available for types that can be converted to a string |
| 817 | template <typename X> Option *default_val(const X &val) { |
| 818 | std::string val_str = detail::value_string(val); |
| 819 | auto old_option_state = current_option_state_; |
| 820 | results_t old_results{std::move(results_)}; |
| 821 | results_.clear(); |
| 822 | try { |
| 823 | add_result(val_str); |
| 824 | // if trigger_on_result_ is set the callback already ran |
| 825 | if(run_callback_for_default_ && !trigger_on_result_) { |
| 826 | run_callback(); // run callback sets the state, we need to reset it again |
| 827 | current_option_state_ = option_state::parsing; |
| 828 | } else { |
| 829 | _validate_results(results_); |
| 830 | current_option_state_ = old_option_state; |
| 831 | } |
| 832 | } catch(const ConversionError &err) { |
| 833 | // this should be done |
| 834 | results_ = std::move(old_results); |
| 835 | current_option_state_ = old_option_state; |
| 836 | |
| 837 | throw ConversionError( |
| 838 | get_name(), std::string("given default value(\"") + val_str + "\") produces an error : " + err.what()); |
| 839 | } catch(const CLI::Error &) { |
| 840 | results_ = std::move(old_results); |
| 841 | current_option_state_ = old_option_state; |
| 842 | throw; |
| 843 | } |
| 844 | results_ = std::move(old_results); |
| 845 | default_str_ = std::move(val_str); |
| 846 | return this; |
| 847 | } |
| 848 | |
| 849 | /// Get the full typename for this option |
| 850 | CLI11_NODISCARD std::string get_type_name() const; |
nothing calls this directly
no test coverage detected