CLI11
C++11 Command Line Interface Parser
Loading...
Searching...
No Matches
Option_inl.hpp
1// Copyright (c) 2017-2024, University of Cincinnati, developed by Henry Schreiner
2// under NSF AWARD 1414736 and by the respective contributors.
3// All rights reserved.
4//
5// SPDX-License-Identifier: BSD-3-Clause
6
7#pragma once
8
9// IWYU pragma: private, include "CLI/CLI.hpp"
10
11// This include is only needed for IDEs to discover symbols
12#include "../Option.hpp"
13
14// [CLI11:public_includes:set]
15#include <algorithm>
16#include <string>
17#include <utility>
18#include <vector>
19// [CLI11:public_includes:end]
20
21namespace CLI {
22// [CLI11:option_inl_hpp:verbatim]
23
24template <typename CRTP> template <typename T> void OptionBase<CRTP>::copy_to(T *other) const {
25 other->group(group_);
26 other->required(required_);
27 other->ignore_case(ignore_case_);
28 other->ignore_underscore(ignore_underscore_);
29 other->configurable(configurable_);
30 other->disable_flag_override(disable_flag_override_);
31 other->delimiter(delimiter_);
32 other->always_capture_default(always_capture_default_);
33 other->multi_option_policy(multi_option_policy_);
34}
35
36CLI11_INLINE Option *Option::expected(int value) {
37 if(value < 0) {
38 expected_min_ = -value;
41 }
42 allow_extra_args_ = true;
43 flag_like_ = false;
44 } else if(value == detail::expected_max_vector_size) {
45 expected_min_ = 1;
46 expected_max_ = detail::expected_max_vector_size;
47 allow_extra_args_ = true;
48 flag_like_ = false;
49 } else {
50 expected_min_ = value;
51 expected_max_ = value;
53 }
54 return this;
55}
56
57CLI11_INLINE Option *Option::expected(int value_min, int value_max) {
58 if(value_min < 0) {
59 value_min = -value_min;
60 }
61
62 if(value_max < 0) {
63 value_max = detail::expected_max_vector_size;
64 }
65 if(value_max < value_min) {
66 expected_min_ = value_max;
67 expected_max_ = value_min;
68 } else {
69 expected_max_ = value_max;
70 expected_min_ = value_min;
71 }
72
73 return this;
74}
75
76CLI11_INLINE Option *Option::check(Validator validator, const std::string &validator_name) {
77 validator.non_modifying();
78 validators_.push_back(std::move(validator));
79 if(!validator_name.empty())
80 validators_.back().name(validator_name);
81 return this;
82}
83
84CLI11_INLINE Option *Option::check(std::function<std::string(const std::string &)> Validator,
85 std::string Validator_description,
86 std::string Validator_name) {
87 validators_.emplace_back(Validator, std::move(Validator_description), std::move(Validator_name));
88 validators_.back().non_modifying();
89 return this;
90}
91
92CLI11_INLINE Option *Option::transform(Validator Validator, const std::string &Validator_name) {
93 validators_.insert(validators_.begin(), std::move(Validator));
94 if(!Validator_name.empty())
95 validators_.front().name(Validator_name);
96 return this;
97}
98
99CLI11_INLINE Option *Option::transform(const std::function<std::string(std::string)> &func,
100 std::string transform_description,
101 std::string transform_name) {
102 validators_.insert(validators_.begin(),
103 Validator(
104 [func](std::string &val) {
105 val = func(val);
106 return std::string{};
107 },
108 std::move(transform_description),
109 std::move(transform_name)));
110
111 return this;
112}
113
114CLI11_INLINE Option *Option::each(const std::function<void(std::string)> &func) {
115 validators_.emplace_back(
116 [func](std::string &inout) {
117 func(inout);
118 return std::string{};
119 },
120 std::string{});
121 return this;
122}
123
124CLI11_INLINE Validator *Option::get_validator(const std::string &Validator_name) {
125 for(auto &Validator : validators_) {
126 if(Validator_name == Validator.get_name()) {
127 return &Validator;
128 }
129 }
130 if((Validator_name.empty()) && (!validators_.empty())) {
131 return &(validators_.front());
132 }
133 throw OptionNotFound(std::string{"Validator "} + Validator_name + " Not Found");
134}
135
136CLI11_INLINE Validator *Option::get_validator(int index) {
137 // This is an signed int so that it is not equivalent to a pointer.
138 if(index >= 0 && index < static_cast<int>(validators_.size())) {
139 return &(validators_[static_cast<decltype(validators_)::size_type>(index)]);
140 }
141 throw OptionNotFound("Validator index is not valid");
142}
143
144CLI11_INLINE bool Option::remove_needs(Option *opt) {
145 auto iterator = std::find(std::begin(needs_), std::end(needs_), opt);
146
147 if(iterator == std::end(needs_)) {
148 return false;
149 }
150 needs_.erase(iterator);
151 return true;
152}
153
154CLI11_INLINE Option *Option::excludes(Option *opt) {
155 if(opt == this) {
156 throw(IncorrectConstruction("and option cannot exclude itself"));
157 }
158 excludes_.insert(opt);
159
160 // Help text should be symmetric - excluding a should exclude b
161 opt->excludes_.insert(this);
162
163 // Ignoring the insert return value, excluding twice is now allowed.
164 // (Mostly to allow both directions to be excluded by user, even though the library does it for you.)
165
166 return this;
167}
168
169CLI11_INLINE bool Option::remove_excludes(Option *opt) {
170 auto iterator = std::find(std::begin(excludes_), std::end(excludes_), opt);
171
172 if(iterator == std::end(excludes_)) {
173 return false;
174 }
175 excludes_.erase(iterator);
176 return true;
177}
178
179template <typename T> Option *Option::ignore_case(bool value) {
180 if(!ignore_case_ && value) {
181 ignore_case_ = value;
182 auto *parent = static_cast<T *>(parent_);
183 for(const Option_p &opt : parent->options_) {
184 if(opt.get() == this) {
185 continue;
186 }
187 const auto &omatch = opt->matching_name(*this);
188 if(!omatch.empty()) {
189 ignore_case_ = false;
190 throw OptionAlreadyAdded("adding ignore case caused a name conflict with " + omatch);
191 }
192 }
193 } else {
194 ignore_case_ = value;
195 }
196 return this;
197}
198
199template <typename T> Option *Option::ignore_underscore(bool value) {
200
201 if(!ignore_underscore_ && value) {
202 ignore_underscore_ = value;
203 auto *parent = static_cast<T *>(parent_);
204 for(const Option_p &opt : parent->options_) {
205 if(opt.get() == this) {
206 continue;
207 }
208 const auto &omatch = opt->matching_name(*this);
209 if(!omatch.empty()) {
210 ignore_underscore_ = false;
211 throw OptionAlreadyAdded("adding ignore underscore caused a name conflict with " + omatch);
212 }
213 }
214 } else {
215 ignore_underscore_ = value;
216 }
217 return this;
218}
219
220CLI11_INLINE Option *Option::multi_option_policy(MultiOptionPolicy value) {
221 if(value != multi_option_policy_) {
222 if(multi_option_policy_ == MultiOptionPolicy::Throw && expected_max_ == detail::expected_max_vector_size &&
223 expected_min_ > 1) { // this bizarre condition is to maintain backwards compatibility
224 // with the previous behavior of expected_ with vectors
226 }
227 multi_option_policy_ = value;
229 }
230 return this;
231}
232
233CLI11_NODISCARD CLI11_INLINE std::string Option::get_name(bool positional, bool all_options) const {
234 if(get_group().empty())
235 return {}; // Hidden
236
237 if(all_options) {
238
239 std::vector<std::string> name_list;
240
242 if((positional && (!pname_.empty())) || (snames_.empty() && lnames_.empty())) {
243 name_list.push_back(pname_);
244 }
245 if((get_items_expected() == 0) && (!fnames_.empty())) {
246 for(const std::string &sname : snames_) {
247 name_list.push_back("-" + sname);
248 if(check_fname(sname)) {
249 name_list.back() += "{" + get_flag_value(sname, "") + "}";
250 }
251 }
252
253 for(const std::string &lname : lnames_) {
254 name_list.push_back("--" + lname);
255 if(check_fname(lname)) {
256 name_list.back() += "{" + get_flag_value(lname, "") + "}";
257 }
258 }
259 } else {
260 for(const std::string &sname : snames_)
261 name_list.push_back("-" + sname);
262
263 for(const std::string &lname : lnames_)
264 name_list.push_back("--" + lname);
265 }
266
267 return detail::join(name_list);
268 }
269
270 // This returns the positional name no matter what
271 if(positional)
272 return pname_;
273
274 // Prefer long name
275 if(!lnames_.empty())
276 return std::string(2, '-') + lnames_[0];
277
278 // Or short name if no long name
279 if(!snames_.empty())
280 return std::string(1, '-') + snames_[0];
281
282 // If positional is the only name, it's okay to use that
283 return pname_;
284}
285
286CLI11_INLINE void Option::run_callback() {
287 bool used_default_str = false;
288 if(force_callback_ && results_.empty()) {
289 used_default_str = true;
291 }
293 _validate_results(results_);
295 }
296
298 _reduce_results(proc_results_, results_);
299 }
300
302 if(callback_) {
303 const results_t &send_results = proc_results_.empty() ? results_ : proc_results_;
304 bool local_result = callback_(send_results);
305 if(used_default_str) {
306 // we only clear the results if the callback was actually used
307 // otherwise the callback is the storage of the default
308 results_.clear();
309 proc_results_.clear();
310 }
311 if(!local_result)
313 }
314}
315
316CLI11_NODISCARD CLI11_INLINE const std::string &Option::matching_name(const Option &other) const {
317 static const std::string estring;
318 bool bothConfigurable = configurable_ && other.configurable_;
319 for(const std::string &sname : snames_) {
320 if(other.check_sname(sname))
321 return sname;
322 if(bothConfigurable && other.check_lname(sname))
323 return sname;
324 }
325 for(const std::string &lname : lnames_) {
326 if(other.check_lname(lname))
327 return lname;
328 if(lname.size() == 1 && bothConfigurable) {
329 if(other.check_sname(lname)) {
330 return lname;
331 }
332 }
333 }
334 if(bothConfigurable && snames_.empty() && lnames_.empty() && !pname_.empty()) {
335 if(other.check_sname(pname_) || other.check_lname(pname_) || pname_ == other.pname_)
336 return pname_;
337 }
338 if(bothConfigurable && other.snames_.empty() && other.fnames_.empty() && !other.pname_.empty()) {
339 if(check_sname(other.pname_) || check_lname(other.pname_) || (pname_ == other.pname_))
340 return other.pname_;
341 }
342 if(ignore_case_ ||
343 ignore_underscore_) { // We need to do the inverse, in case we are ignore_case or ignore underscore
344 for(const std::string &sname : other.snames_)
345 if(check_sname(sname))
346 return sname;
347 for(const std::string &lname : other.lnames_)
348 if(check_lname(lname))
349 return lname;
350 }
351 return estring;
352}
353
354CLI11_NODISCARD CLI11_INLINE bool Option::check_name(const std::string &name) const {
355
356 if(name.length() > 2 && name[0] == '-' && name[1] == '-')
357 return check_lname(name.substr(2));
358 if(name.length() > 1 && name.front() == '-')
359 return check_sname(name.substr(1));
360 if(!pname_.empty()) {
361 std::string local_pname = pname_;
362 std::string local_name = name;
364 local_pname = detail::remove_underscore(local_pname);
365 local_name = detail::remove_underscore(local_name);
366 }
367 if(ignore_case_) {
368 local_pname = detail::to_lower(local_pname);
369 local_name = detail::to_lower(local_name);
370 }
371 if(local_name == local_pname) {
372 return true;
373 }
374 }
375
376 if(!envname_.empty()) {
377 // this needs to be the original since envname_ shouldn't match on case insensitivity
378 return (name == envname_);
379 }
380 return false;
381}
382
383CLI11_NODISCARD CLI11_INLINE std::string Option::get_flag_value(const std::string &name,
384 std::string input_value) const {
385 static const std::string trueString{"true"};
386 static const std::string falseString{"false"};
387 static const std::string emptyString{"{}"};
388 // check for disable flag override_
390 if(!((input_value.empty()) || (input_value == emptyString))) {
391 auto default_ind = detail::find_member(name, fnames_, ignore_case_, ignore_underscore_);
392 if(default_ind >= 0) {
393 // We can static cast this to std::size_t because it is more than 0 in this block
394 if(default_flag_values_[static_cast<std::size_t>(default_ind)].second != input_value) {
395 if(input_value == default_str_ && force_callback_) {
396 return input_value;
397 }
398 throw(ArgumentMismatch::FlagOverride(name));
399 }
400 } else {
401 if(input_value != trueString) {
402 throw(ArgumentMismatch::FlagOverride(name));
403 }
404 }
405 }
406 }
407 auto ind = detail::find_member(name, fnames_, ignore_case_, ignore_underscore_);
408 if((input_value.empty()) || (input_value == emptyString)) {
409 if(flag_like_) {
410 return (ind < 0) ? trueString : default_flag_values_[static_cast<std::size_t>(ind)].second;
411 }
412 return (ind < 0) ? default_str_ : default_flag_values_[static_cast<std::size_t>(ind)].second;
413 }
414 if(ind < 0) {
415 return input_value;
416 }
417 if(default_flag_values_[static_cast<std::size_t>(ind)].second == falseString) {
418 errno = 0;
419 auto val = detail::to_flag_value(input_value);
420 if(errno != 0) {
421 errno = 0;
422 return input_value;
423 }
424 return (val == 1) ? falseString : (val == (-1) ? trueString : std::to_string(-val));
425 }
426 return input_value;
427}
428
429CLI11_INLINE Option *Option::add_result(std::string s) {
430 _add_result(std::move(s), results_);
432 return this;
433}
434
435CLI11_INLINE Option *Option::add_result(std::string s, int &results_added) {
436 results_added = _add_result(std::move(s), results_);
438 return this;
439}
440
441CLI11_INLINE Option *Option::add_result(std::vector<std::string> s) {
443 for(auto &str : s) {
444 _add_result(std::move(str), results_);
445 }
446 return this;
447}
448
449CLI11_NODISCARD CLI11_INLINE results_t Option::reduced_results() const {
450 results_t res = proc_results_.empty() ? results_ : proc_results_;
453 res = results_;
454 _validate_results(res);
455 }
456 if(!res.empty()) {
457 results_t extra;
458 _reduce_results(extra, res);
459 if(!extra.empty()) {
460 res = std::move(extra);
461 }
462 }
463 }
464 return res;
465}
466
467CLI11_INLINE Option *Option::type_size(int option_type_size) {
468 if(option_type_size < 0) {
469 // this section is included for backwards compatibility
470 type_size_max_ = -option_type_size;
471 type_size_min_ = -option_type_size;
472 expected_max_ = detail::expected_max_vector_size;
473 } else {
474 type_size_max_ = option_type_size;
475 if(type_size_max_ < detail::expected_max_vector_size) {
476 type_size_min_ = option_type_size;
477 } else {
478 inject_separator_ = true;
479 }
480 if(type_size_max_ == 0)
481 required_ = false;
482 }
483 return this;
484}
485
486CLI11_INLINE Option *Option::type_size(int option_type_size_min, int option_type_size_max) {
487 if(option_type_size_min < 0 || option_type_size_max < 0) {
488 // this section is included for backwards compatibility
489 expected_max_ = detail::expected_max_vector_size;
490 option_type_size_min = (std::abs)(option_type_size_min);
491 option_type_size_max = (std::abs)(option_type_size_max);
492 }
493
494 if(option_type_size_min > option_type_size_max) {
495 type_size_max_ = option_type_size_min;
496 type_size_min_ = option_type_size_max;
497 } else {
498 type_size_min_ = option_type_size_min;
499 type_size_max_ = option_type_size_max;
500 }
501 if(type_size_max_ == 0) {
502 required_ = false;
503 }
504 if(type_size_max_ >= detail::expected_max_vector_size) {
505 inject_separator_ = true;
506 }
507 return this;
508}
509
510CLI11_NODISCARD CLI11_INLINE std::string Option::get_type_name() const {
511 std::string full_type_name = type_name_();
512 if(!validators_.empty()) {
513 for(const auto &Validator : validators_) {
514 std::string vtype = Validator.get_description();
515 if(!vtype.empty()) {
516 full_type_name += ":" + vtype;
517 }
518 }
519 }
520 return full_type_name;
521}
522
523CLI11_INLINE void Option::_validate_results(results_t &res) const {
524 // Run the Validators (can change the string)
525 if(!validators_.empty()) {
526 if(type_size_max_ > 1) { // in this context index refers to the index in the type
527 int index = 0;
528 if(get_items_expected_max() < static_cast<int>(res.size()) &&
529 (multi_option_policy_ == CLI::MultiOptionPolicy::TakeLast ||
530 multi_option_policy_ == CLI::MultiOptionPolicy::Reverse)) {
531 // create a negative index for the earliest ones
532 index = get_items_expected_max() - static_cast<int>(res.size());
533 }
534
535 for(std::string &result : res) {
536 if(detail::is_separator(result) && type_size_max_ != type_size_min_ && index >= 0) {
537 index = 0; // reset index for variable size chunks
538 continue;
539 }
540 auto err_msg = _validate(result, (index >= 0) ? (index % type_size_max_) : index);
541 if(!err_msg.empty())
542 throw ValidationError(get_name(), err_msg);
543 ++index;
544 }
545 } else {
546 int index = 0;
547 if(expected_max_ < static_cast<int>(res.size()) &&
548 (multi_option_policy_ == CLI::MultiOptionPolicy::TakeLast ||
549 multi_option_policy_ == CLI::MultiOptionPolicy::Reverse)) {
550 // create a negative index for the earliest ones
551 index = expected_max_ - static_cast<int>(res.size());
552 }
553 for(std::string &result : res) {
554 auto err_msg = _validate(result, index);
555 ++index;
556 if(!err_msg.empty())
557 throw ValidationError(get_name(), err_msg);
558 }
559 }
560 }
561}
562
563CLI11_INLINE void Option::_reduce_results(results_t &out, const results_t &original) const {
564
565 // max num items expected or length of vector, always at least 1
566 // Only valid for a trimming policy
567
568 out.clear();
569 // Operation depends on the policy setting
570 switch(multi_option_policy_) {
571 case MultiOptionPolicy::TakeAll:
572 break;
573 case MultiOptionPolicy::TakeLast: {
574 // Allow multi-option sizes (including 0)
575 std::size_t trim_size = std::min<std::size_t>(
576 static_cast<std::size_t>(std::max<int>(get_items_expected_max(), 1)), original.size());
577 if(original.size() != trim_size) {
578 out.assign(original.end() - static_cast<results_t::difference_type>(trim_size), original.end());
579 }
580 } break;
581 case MultiOptionPolicy::Reverse: {
582 // Allow multi-option sizes (including 0)
583 std::size_t trim_size = std::min<std::size_t>(
584 static_cast<std::size_t>(std::max<int>(get_items_expected_max(), 1)), original.size());
585 if(original.size() != trim_size || trim_size > 1) {
586 out.assign(original.end() - static_cast<results_t::difference_type>(trim_size), original.end());
587 }
588 std::reverse(out.begin(), out.end());
589 } break;
590 case MultiOptionPolicy::TakeFirst: {
591 std::size_t trim_size = std::min<std::size_t>(
592 static_cast<std::size_t>(std::max<int>(get_items_expected_max(), 1)), original.size());
593 if(original.size() != trim_size) {
594 out.assign(original.begin(), original.begin() + static_cast<results_t::difference_type>(trim_size));
595 }
596 } break;
597 case MultiOptionPolicy::Join:
598 if(results_.size() > 1) {
599 out.push_back(detail::join(original, std::string(1, (delimiter_ == '\0') ? '\n' : delimiter_)));
600 }
601 break;
602 case MultiOptionPolicy::Sum:
603 out.push_back(detail::sum_string_vector(original));
604 break;
605 case MultiOptionPolicy::Throw:
606 default: {
607 auto num_min = static_cast<std::size_t>(get_items_expected_min());
608 auto num_max = static_cast<std::size_t>(get_items_expected_max());
609 if(num_min == 0) {
610 num_min = 1;
611 }
612 if(num_max == 0) {
613 num_max = 1;
614 }
615 if(original.size() < num_min) {
616 throw ArgumentMismatch::AtLeast(get_name(), static_cast<int>(num_min), original.size());
617 }
618 if(original.size() > num_max) {
619 if(original.size() == 2 && num_max == 1 && original[1] == "%%" && original[0] == "{}") {
620 // this condition is a trap for the following empty indicator check on config files
621 out = original;
622 } else {
623 throw ArgumentMismatch::AtMost(get_name(), static_cast<int>(num_max), original.size());
624 }
625 }
626 break;
627 }
628 }
629 // this check is to allow an empty vector in certain circumstances but not if expected is not zero.
630 // {} is the indicator for an empty container
631 if(out.empty()) {
632 if(original.size() == 1 && original[0] == "{}" && get_items_expected_min() > 0) {
633 out.emplace_back("{}");
634 out.emplace_back("%%");
635 }
636 } else if(out.size() == 1 && out[0] == "{}" && get_items_expected_min() > 0) {
637 out.emplace_back("%%");
638 }
639}
640
641CLI11_INLINE std::string Option::_validate(std::string &result, int index) const {
642 std::string err_msg;
643 if(result.empty() && expected_min_ == 0) {
644 // an empty with nothing expected is allowed
645 return err_msg;
646 }
647 for(const auto &vali : validators_) {
648 auto v = vali.get_application_index();
649 if(v == -1 || v == index) {
650 try {
651 err_msg = vali(result);
652 } catch(const ValidationError &err) {
653 err_msg = err.what();
654 }
655 if(!err_msg.empty())
656 break;
657 }
658 }
659
660 return err_msg;
661}
662
663CLI11_INLINE int Option::_add_result(std::string &&result, std::vector<std::string> &res) const {
664 int result_count = 0;
665 if((allow_extra_args_ || get_expected_max() > 1) && !result.empty() && result.front() == '[' &&
666 result.back() == ']') { // this is now a vector string likely from the default or user entry
667 result.pop_back();
668
669 for(auto &var : CLI::detail::split_up(result.substr(1), ',')) {
670 if(!var.empty()) {
671 result_count += _add_result(std::move(var), res);
672 }
673 }
674 return result_count;
675 }
676 if(delimiter_ == '\0') {
677 res.push_back(std::move(result));
678 ++result_count;
679 } else {
680 if((result.find_first_of(delimiter_) != std::string::npos)) {
681 for(const auto &var : CLI::detail::split(result, delimiter_)) {
682 if(!var.empty()) {
683 res.push_back(var);
684 ++result_count;
685 }
686 }
687 } else {
688 res.push_back(std::move(result));
689 ++result_count;
690 }
691 }
692 return result_count;
693}
694// [CLI11:option_inl_hpp:end]
695} // namespace CLI
Thrown when conversion call back fails, such as when an int fails to coerce to a string.
Definition Error.hpp:205
Thrown when an option is set to conflicting values (non-vector and multi args, for example)
Definition Error.hpp:96
Thrown when an option already exists.
Definition Error.hpp:144
MultiOptionPolicy multi_option_policy_
Policy for handling multiple arguments beyond the expected Max.
Definition Option.hpp:81
bool ignore_case_
Ignore the case when matching (option, not value)
Definition Option.hpp:63
bool configurable_
Allow this option to be given in a configuration file.
Definition Option.hpp:69
bool disable_flag_override_
Disable overriding flag values with '=value'.
Definition Option.hpp:72
bool required_
True if this is a required option.
Definition Option.hpp:60
char delimiter_
Specify a delimiter character for vector arguments.
Definition Option.hpp:75
bool ignore_underscore_
Ignore underscores when matching (option, not value)
Definition Option.hpp:66
CLI11_NODISCARD const std::string & get_group() const
Get the group of this option.
Definition Option.hpp:115
void copy_to(T *other) const
Copy the contents to another similar class (one based on OptionBase)
Definition Option_inl.hpp:24
Definition Option.hpp:231
Option * type_size(int option_type_size)
Set a custom option size.
Definition Option_inl.hpp:467
Option * expected(int value)
Set the number of expected arguments.
Definition Option_inl.hpp:36
std::string default_str_
A human readable default value, either manually set, captured, or captured by default.
Definition Option.hpp:265
CLI11_NODISCARD bool check_name(const std::string &name) const
Check a name. Requires "-" or "--" for short / long, supports positional name.
Definition Option_inl.hpp:354
std::function< std::string()> type_name_
Definition Option.hpp:273
@ reduced
a subset of results has been generated
@ callback_run
the callback has been executed
@ validated
the results have been validated
@ parsing
The option is currently collecting parsed results.
option_state current_option_state_
Whether the callback has run (needed for INI parsing)
Definition Option.hpp:328
int type_size_min_
The minimum number of arguments an option should be expecting.
Definition Option.hpp:286
CLI11_NODISCARD results_t reduced_results() const
Get a copy of the results.
Definition Option_inl.hpp:449
CLI11_NODISCARD std::string get_type_name() const
Get the full typename for this option.
Definition Option_inl.hpp:510
CLI11_NODISCARD bool check_fname(std::string name) const
Requires "--" to be removed from string.
Definition Option.hpp:650
std::string pname_
A positional name.
Definition Option.hpp:252
int expected_min_
The minimum number of expected values.
Definition Option.hpp:289
Option * ignore_case(bool value=true)
Definition Option_inl.hpp:179
std::set< Option * > needs_
A list of options that are required with this option.
Definition Option.hpp:297
void run_callback()
Process the callback.
Definition Option_inl.hpp:286
CLI11_NODISCARD bool check_sname(std::string name) const
Requires "-" to be removed from string.
Definition Option.hpp:640
bool flag_like_
Specify that the option should act like a flag vs regular option.
Definition Option.hpp:332
CLI11_NODISCARD std::string get_name(bool positional=false, bool all_options=false) const
Gets a comma separated list of names. Will include / prefer the positional name if positional is true...
Definition Option_inl.hpp:233
std::set< Option * > excludes_
A list of options that are excluded with this option.
Definition Option.hpp:300
bool force_callback_
flag indicating that the option should force the callback regardless if any results present
Definition Option.hpp:340
std::vector< std::string > fnames_
a list of flag names with specified default values;
Definition Option.hpp:249
CLI11_NODISCARD int get_items_expected_min() const
The total min number of expected string values to be used.
Definition Option.hpp:576
CLI11_NODISCARD const std::string & matching_name(const Option &other) const
If options share any of the same names, find it.
Definition Option_inl.hpp:316
CLI11_NODISCARD bool check_lname(std::string name) const
Requires "--" to be removed from string.
Definition Option.hpp:645
CLI11_NODISCARD int get_items_expected_max() const
Get the maximum number of items expected to be returned and used for the callback.
Definition Option.hpp:579
std::vector< std::string > snames_
A list of the short names (-a) without the leading dashes.
Definition Option.hpp:239
results_t proc_results_
results after reduction
Definition Option.hpp:319
bool remove_excludes(Option *opt)
Remove needs link from an option. Returns true if the option really was in the needs list.
Definition Option_inl.hpp:169
Option * multi_option_policy(MultiOptionPolicy value=MultiOptionPolicy::Throw)
Take the last argument if given multiple times (or another policy)
Definition Option_inl.hpp:220
Option * excludes(Option *opt)
Sets excluded options.
Definition Option_inl.hpp:154
App * parent_
link back up to the parent App for fallthrough
Definition Option.hpp:307
int expected_max_
The maximum number of expected values.
Definition Option.hpp:291
CLI11_NODISCARD std::string get_flag_value(const std::string &name, std::string input_value) const
Definition Option_inl.hpp:383
CLI11_NODISCARD int get_items_expected() const
The total min number of expected string values to be used.
Definition Option.hpp:584
Validator * get_validator(const std::string &Validator_name="")
Get a named Validator.
Definition Option_inl.hpp:124
bool inject_separator_
flag indicating a separator needs to be injected after each argument call
Definition Option.hpp:336
Option * check(Validator validator, const std::string &validator_name="")
Adds a Validator with a built in type name.
Definition Option_inl.hpp:76
callback_t callback_
Options store a callback to do all the work.
Definition Option.hpp:310
CLI11_NODISCARD bool empty() const
True if the option was not passed.
Definition Option.hpp:364
CLI11_NODISCARD int get_expected_max() const
The max number of times the option expects to be included.
Definition Option.hpp:573
std::string envname_
If given, check the environment for this option.
Definition Option.hpp:255
Option * ignore_underscore(bool value=true)
Definition Option_inl.hpp:199
std::vector< std::pair< std::string, std::string > > default_flag_values_
Definition Option.hpp:246
std::vector< Validator > validators_
A list of Validators to run on each value parsed.
Definition Option.hpp:294
int type_size_max_
Definition Option.hpp:284
bool allow_extra_args_
Specify that extra args beyond type_size_max should be allowed.
Definition Option.hpp:330
Option * transform(Validator Validator, const std::string &Validator_name="")
Adds a transforming Validator with a built in type name.
Definition Option_inl.hpp:92
std::vector< std::string > lnames_
A list of the long names (--long) without the leading dashes.
Definition Option.hpp:242
Option * add_result(std::string s)
Puts a result at the end.
Definition Option_inl.hpp:429
bool remove_needs(Option *opt)
Remove needs link from an option. Returns true if the option really was in the needs list.
Definition Option_inl.hpp:144
Option * each(const std::function< void(std::string)> &func)
Adds a user supplied function to run on each item passed in (communicate though lambda capture)
Definition Option_inl.hpp:114
results_t results_
complete Results of parsing
Definition Option.hpp:317
Thrown when counting a non-existent option.
Definition Error.hpp:351
Some validators that are provided.
Definition Validators.hpp:55
CLI11_NODISCARD std::string get_description() const
Generate type description information for the Validator.
Definition Validators.hpp:108
CLI11_NODISCARD const std::string & get_name() const
Get the name of the Validator.
Definition Validators.hpp:126