Skip to content

Commit d9379cc

Browse files
cbachhuberhenryiii
authored andcommitted
Clang-tidy fixes (#360)
* Clang-tidy fixes * Format * Satisfy pre-commit hooks * Fix getters to constref return * Final name getter as constref
1 parent fc0f82a commit d9379cc

File tree

2 files changed

+19
-17
lines changed

2 files changed

+19
-17
lines changed

include/CLI/Option.hpp

+18-16
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ template <typename CRTP> class OptionBase {
8787
// setters
8888

8989
/// Changes the group membership
90-
CRTP *group(std::string name) {
90+
CRTP *group(const std::string &name) {
9191
group_ = name;
9292
return static_cast<CRTP *>(this);
9393
}
@@ -346,7 +346,7 @@ class Option : public OptionBase<Option> {
346346
bool empty() const { return results_.empty(); }
347347

348348
/// This class is true if option is passed.
349-
operator bool() const { return !empty(); }
349+
explicit operator bool() const { return !empty(); }
350350

351351
/// Clear the parsed results (mostly for testing)
352352
void clear() {
@@ -409,7 +409,7 @@ class Option : public OptionBase<Option> {
409409
bool get_allow_extra_args() const { return allow_extra_args_; }
410410

411411
/// 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 = "") {
413413
validator.non_modifying();
414414
validators_.push_back(std::move(validator));
415415
if(!validator_name.empty())
@@ -427,15 +427,15 @@ class Option : public OptionBase<Option> {
427427
}
428428

429429
/// 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 = "") {
431431
validators_.insert(validators_.begin(), std::move(Validator));
432432
if(!Validator_name.empty())
433433
validators_.front().name(Validator_name);
434434
return this;
435435
}
436436

437437
/// 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,
439439
std::string transform_description = "",
440440
std::string transform_name = "") {
441441
validators_.insert(validators_.begin(),
@@ -451,7 +451,7 @@ class Option : public OptionBase<Option> {
451451
}
452452

453453
/// 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) {
455455
validators_.emplace_back(
456456
[func](std::string &inout) {
457457
func(inout);
@@ -559,7 +559,7 @@ class Option : public OptionBase<Option> {
559559

560560
/// Sets environment variable to read if no option given
561561
Option *envname(std::string name) {
562-
envname_ = name;
562+
envname_ = std::move(name);
563563
return this;
564564
}
565565

@@ -663,13 +663,13 @@ class Option : public OptionBase<Option> {
663663
callback_t get_callback() const { return callback_; }
664664

665665
/// 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_; }
667667

668668
/// 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_; }
670670

671671
/// 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_; }
673673

674674
/// The number of times the option expects to be included
675675
int get_expected() const { return expected_min_; }
@@ -845,24 +845,26 @@ class Option : public OptionBase<Option> {
845845
}
846846

847847
/// 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+
}
849851

850852
/// Requires "--" to be removed from string
851853
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);
853855
}
854856

855857
/// Requires "--" to be removed from string
856858
bool check_fname(std::string name) const {
857859
if(fnames_.empty()) {
858860
return false;
859861
}
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);
861863
}
862864

863865
/// Get the value that goes for a flag, nominally gets the default value but allows for overrides if not
864866
/// 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 {
866868
static const std::string trueString{"true"};
867869
static const std::string falseString{"false"};
868870
static const std::string emptyString{"{}"};
@@ -1061,12 +1063,12 @@ class Option : public OptionBase<Option> {
10611063

10621064
/// Set the default value string representation (does not change the contained value)
10631065
Option *default_str(std::string val) {
1064-
default_str_ = val;
1066+
default_str_ = std::move(val);
10651067
return this;
10661068
}
10671069

10681070
/// 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) {
10701072
default_str(val);
10711073
auto old_results = results_;
10721074
results_.clear();

include/CLI/Validators.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ class Validator {
5454
/// This is the description function, if empty the description_ will be used
5555
std::function<std::string()> desc_function_{[]() { return std::string{}; }};
5656

57-
/// This it the base function that is to be called.
57+
/// This is the base function that is to be called.
5858
/// Returns a string error message if validation fails.
5959
std::function<std::string(std::string &)> func_{[](std::string &) { return std::string{}; }};
6060
/// The name for search purposes of the Validator

0 commit comments

Comments
 (0)