Commit d9379cccf574c7a5a5f5b1e2699cbd67435087e3

Authored by Christoph Bachhuber
Committed by Henry Schreiner
1 parent fc0f82a8

Clang-tidy fixes (#360)

* Clang-tidy fixes

* Format

* Satisfy pre-commit hooks

* Fix getters to constref return

* Final name getter as constref
include/CLI/Option.hpp
... ... @@ -87,7 +87,7 @@ template <typename CRTP> class OptionBase {
87 87 // setters
88 88  
89 89 /// Changes the group membership
90   - CRTP *group(std::string name) {
  90 + CRTP *group(const std::string &name) {
91 91 group_ = name;
92 92 return static_cast<CRTP *>(this);
93 93 }
... ... @@ -346,7 +346,7 @@ class Option : public OptionBase&lt;Option&gt; {
346 346 bool empty() const { return results_.empty(); }
347 347  
348 348 /// This class is true if option is passed.
349   - operator bool() const { return !empty(); }
  349 + explicit operator bool() const { return !empty(); }
350 350  
351 351 /// Clear the parsed results (mostly for testing)
352 352 void clear() {
... ... @@ -409,7 +409,7 @@ class Option : public OptionBase&lt;Option&gt; {
409 409 bool get_allow_extra_args() const { return allow_extra_args_; }
410 410  
411 411 /// Adds a Validator with a built in type name
412   - Option *check(Validator validator, std::string validator_name = "") {
  412 + Option *check(Validator validator, const std::string &validator_name = "") {
413 413 validator.non_modifying();
414 414 validators_.push_back(std::move(validator));
415 415 if(!validator_name.empty())
... ... @@ -427,7 +427,7 @@ class Option : public OptionBase&lt;Option&gt; {
427 427 }
428 428  
429 429 /// Adds a transforming Validator with a built in type name
430   - Option *transform(Validator Validator, std::string Validator_name = "") {
  430 + Option *transform(Validator Validator, const std::string &Validator_name = "") {
431 431 validators_.insert(validators_.begin(), std::move(Validator));
432 432 if(!Validator_name.empty())
433 433 validators_.front().name(Validator_name);
... ... @@ -435,7 +435,7 @@ class Option : public OptionBase&lt;Option&gt; {
435 435 }
436 436  
437 437 /// Adds a Validator-like function that can change result
438   - Option *transform(std::function<std::string(std::string)> func,
  438 + Option *transform(const std::function<std::string(std::string)> &func,
439 439 std::string transform_description = "",
440 440 std::string transform_name = "") {
441 441 validators_.insert(validators_.begin(),
... ... @@ -451,7 +451,7 @@ class Option : public OptionBase&lt;Option&gt; {
451 451 }
452 452  
453 453 /// Adds a user supplied function to run on each item passed in (communicate though lambda capture)
454   - Option *each(std::function<void(std::string)> func) {
  454 + Option *each(const std::function<void(std::string)> &func) {
455 455 validators_.emplace_back(
456 456 [func](std::string &inout) {
457 457 func(inout);
... ... @@ -559,7 +559,7 @@ class Option : public OptionBase&lt;Option&gt; {
559 559  
560 560 /// Sets environment variable to read if no option given
561 561 Option *envname(std::string name) {
562   - envname_ = name;
  562 + envname_ = std::move(name);
563 563 return this;
564 564 }
565 565  
... ... @@ -663,13 +663,13 @@ class Option : public OptionBase&lt;Option&gt; {
663 663 callback_t get_callback() const { return callback_; }
664 664  
665 665 /// Get the long names
666   - const std::vector<std::string> get_lnames() const { return lnames_; }
  666 + const std::vector<std::string> &get_lnames() const { return lnames_; }
667 667  
668 668 /// Get the short names
669   - const std::vector<std::string> get_snames() const { return snames_; }
  669 + const std::vector<std::string> &get_snames() const { return snames_; }
670 670  
671 671 /// Get the flag names with specified default values
672   - const std::vector<std::string> get_fnames() const { return fnames_; }
  672 + const std::vector<std::string> &get_fnames() const { return fnames_; }
673 673  
674 674 /// The number of times the option expects to be included
675 675 int get_expected() const { return expected_min_; }
... ... @@ -845,11 +845,13 @@ class Option : public OptionBase&lt;Option&gt; {
845 845 }
846 846  
847 847 /// Requires "-" to be removed from string
848   - bool check_sname(std::string name) const { return (detail::find_member(name, snames_, ignore_case_) >= 0); }
  848 + bool check_sname(std::string name) const {
  849 + return (detail::find_member(std::move(name), snames_, ignore_case_) >= 0);
  850 + }
849 851  
850 852 /// Requires "--" to be removed from string
851 853 bool check_lname(std::string name) const {
852   - return (detail::find_member(name, lnames_, ignore_case_, ignore_underscore_) >= 0);
  854 + return (detail::find_member(std::move(name), lnames_, ignore_case_, ignore_underscore_) >= 0);
853 855 }
854 856  
855 857 /// Requires "--" to be removed from string
... ... @@ -857,12 +859,12 @@ class Option : public OptionBase&lt;Option&gt; {
857 859 if(fnames_.empty()) {
858 860 return false;
859 861 }
860   - return (detail::find_member(name, fnames_, ignore_case_, ignore_underscore_) >= 0);
  862 + return (detail::find_member(std::move(name), fnames_, ignore_case_, ignore_underscore_) >= 0);
861 863 }
862 864  
863 865 /// Get the value that goes for a flag, nominally gets the default value but allows for overrides if not
864 866 /// disabled
865   - std::string get_flag_value(std::string name, std::string input_value) const {
  867 + std::string get_flag_value(const std::string &name, std::string input_value) const {
866 868 static const std::string trueString{"true"};
867 869 static const std::string falseString{"false"};
868 870 static const std::string emptyString{"{}"};
... ... @@ -1061,12 +1063,12 @@ class Option : public OptionBase&lt;Option&gt; {
1061 1063  
1062 1064 /// Set the default value string representation (does not change the contained value)
1063 1065 Option *default_str(std::string val) {
1064   - default_str_ = val;
  1066 + default_str_ = std::move(val);
1065 1067 return this;
1066 1068 }
1067 1069  
1068 1070 /// Set the default value string representation and evaluate into the bound value
1069   - Option *default_val(std::string val) {
  1071 + Option *default_val(const std::string &val) {
1070 1072 default_str(val);
1071 1073 auto old_results = results_;
1072 1074 results_.clear();
... ...
include/CLI/Validators.hpp
... ... @@ -54,7 +54,7 @@ class Validator {
54 54 /// This is the description function, if empty the description_ will be used
55 55 std::function<std::string()> desc_function_{[]() { return std::string{}; }};
56 56  
57   - /// This it the base function that is to be called.
  57 + /// This is the base function that is to be called.
58 58 /// Returns a string error message if validation fails.
59 59 std::function<std::string(std::string &)> func_{[](std::string &) { return std::string{}; }};
60 60 /// The name for search purposes of the Validator
... ...