Commit c781998273f858c81b37cb32c4d02b15ce090239
Committed by
GitHub
1 parent
683ec612
chore: clang tidy updates (#742)
* chore: update clang-tidy Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com> * refactor: address clang-tidy * fix: C++11 support Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com> * chore: two more clang-tidy fixes Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com> * fix: get_inject_separator should be bool * refactor: addressing review feedback Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com> Co-authored-by: Philip Top <phlptp@gmail.com> * Apply suggestions from code review * Update include/CLI/Config.hpp * Update include/CLI/Config.hpp * Update include/CLI/Config.hpp * Update include/CLI/Config.hpp Co-authored-by: Philip Top <phlptp@gmail.com>
Showing
50 changed files
with
970 additions
and
879 deletions
.ci/azure-build.yml
| ... | ... | @@ -8,6 +8,12 @@ steps: |
| 8 | 8 | -DCMAKE_BUILD_TYPE=$(cli11.build_type) $(cli11.options) |
| 9 | 9 | displayName: "Configure" |
| 10 | 10 | |
| 11 | + - script: cmake --build . -- -j2 --keep-going | |
| 12 | + displayName: "Build Unix" | |
| 13 | + workingDirectory: build | |
| 14 | + condition: ne( variables['Agent.OS'], 'Windows_NT' ) | |
| 15 | + | |
| 11 | 16 | - script: cmake --build . |
| 12 | - displayName: "Build" | |
| 17 | + displayName: "Build Windows" | |
| 13 | 18 | workingDirectory: build |
| 19 | + condition: eq( variables['Agent.OS'], 'Windows_NT' ) | ... | ... |
.ci/make_and_test.sh
| ... | ... | @@ -9,7 +9,7 @@ set -evx |
| 9 | 9 | mkdir -p build |
| 10 | 10 | cd build |
| 11 | 11 | cmake .. -DCLI11_WARNINGS_AS_ERRORS=ON -DCLI11_SINGLE_FILE=ON -DCMAKE_CXX_STANDARD="$STD" -DCLI11_SINGLE_FILE_TESTS=ON -DCMAKE_BUILD_TYPE=Debug -DCMAKE_CXX_COMPILER_LAUNCHER=ccache $@ |
| 12 | -cmake --build . -- -j2 | |
| 12 | +cmake --build . -- -j2 --keep-going | |
| 13 | 13 | |
| 14 | 14 | set +evx |
| 15 | 15 | echo -en "travis_fold:end:script.build\\r" | ... | ... |
.clang-tidy
| 1 | 1 | # Checks that will be implemented in future PRs: |
| 2 | 2 | # performance-unnecessary-value-param, hints to ~110 issues. Be careful with implementing the suggested changes of this one, as auto-fixes may break the code |
| 3 | +# bugprone-forwarding-reference-overload probably should be enabled and fixed. | |
| 4 | +# clang-diagnostic-float-equal can be fixed by using _a from Catch::literals | |
| 5 | +# bugprone-exception-escape due to main being a bit simple in examples | |
| 6 | +# modernize-avoid-c-arrays trips up in TEMPLATE_TEST_CASE catch macro | |
| 7 | +# modernize-return-braced-init-list triggers on lambdas ? | |
| 8 | +# modernize-make-unique requires C++14 | |
| 3 | 9 | |
| 4 | -FormatStyle: file | |
| 5 | - | |
| 6 | -Checks: > | |
| 7 | - -*, google-*, -google-runtime-references, llvm-include-order, | |
| 8 | - llvm-namespace-comment, misc-throw-by-value-catch-by-reference, modernize*, | |
| 9 | - -modernize-use-trailing-return-type, readability-container-size-empty, | |
| 10 | - | |
| 11 | -WarningsAsErrors: "*" | |
| 12 | - | |
| 13 | -HeaderFilterRegex: ".*hpp" | |
| 10 | +Checks: | | |
| 11 | + *bugprone*, | |
| 12 | + -bugprone-easily-swappable-parameters, | |
| 13 | + -bugprone-forwarding-reference-overload, | |
| 14 | + -bugprone-exception-escape, | |
| 15 | + clang-analyzer-optin.cplusplus.VirtualCall, | |
| 16 | + clang-analyzer-optin.performance.Padding, | |
| 17 | + -clang-diagnostic-float-equal, | |
| 18 | + cppcoreguidelines-init-variables, | |
| 19 | + cppcoreguidelines-prefer-member-initializer, | |
| 20 | + cppcoreguidelines-pro-type-static-cast-downcast, | |
| 21 | + cppcoreguidelines-slicing, | |
| 22 | + google-*, | |
| 23 | + -google-runtime-references, | |
| 24 | + llvm-include-order, | |
| 25 | + llvm-namespace-comment, | |
| 26 | + misc-definitions-in-headers, | |
| 27 | + misc-misplaced-const, | |
| 28 | + misc-non-copyable-objects, | |
| 29 | + misc-static-assert, | |
| 30 | + misc-throw-by-value-catch-by-reference, | |
| 31 | + misc-throw-by-value-catch-by-reference, | |
| 32 | + misc-uniqueptr-reset-release, | |
| 33 | + misc-unused-parameters, | |
| 34 | + modernize*, | |
| 35 | + -modernize-use-trailing-return-type, | |
| 36 | + -modernize-concat-nested-namespaces, | |
| 37 | + -modernize-return-braced-init-list, | |
| 38 | + -modernize-make-unique, | |
| 39 | + *performance*, | |
| 40 | + -performance-unnecessary-value-param, | |
| 41 | + -performance-inefficient-string-concatenation, | |
| 42 | + readability-avoid-const-params-in-decls, | |
| 43 | + readability-const-return-type, | |
| 44 | + readability-container-size-empty, | |
| 45 | + readability-delete-null-pointer, | |
| 46 | + readability-else-after-return, | |
| 47 | + readability-implicit-bool-conversion, | |
| 48 | + readability-inconsistent-declaration-parameter-name, | |
| 49 | + readability-make-member-function-const, | |
| 50 | + readability-misplaced-array-index, | |
| 51 | + readability-non-const-parameter, | |
| 52 | + readability-qualified-auto, | |
| 53 | + readability-redundant-function-ptr-dereference, | |
| 54 | + readability-redundant-smartptr-get, | |
| 55 | + readability-redundant-string-cstr, | |
| 56 | + readability-simplify-subscript-expr, | |
| 57 | + readability-static-accessed-through-instance, | |
| 58 | + readability-static-definition-in-anonymous-namespace, | |
| 59 | + readability-string-compare, | |
| 60 | + readability-suspicious-call-argument, | |
| 61 | + readability-uniqueptr-delete-release, | |
| 14 | 62 | |
| 15 | 63 | CheckOptions: |
| 16 | 64 | - key: google-readability-braces-around-statements.ShortStatementLines |
| 17 | 65 | value: "3" |
| 66 | + - key: performance-for-range-copy.WarnOnAllAutoCopies | |
| 67 | + value: true | |
| 68 | + - key: performance-inefficient-string-concatenation.StrictMode | |
| 69 | + value: true | |
| 70 | + - key: performance-unnecessary-value-param.AllowedTypes | |
| 71 | + value: "exception_ptr$;" | |
| 72 | + - key: readability-implicit-bool-conversion.AllowPointerConditions | |
| 73 | + value: true | |
| 74 | + - key: modernize-use-nodiscard.ReplacementString | |
| 75 | + value: "CLI11_NODISCARD" | |
| 76 | + | |
| 77 | +HeaderFilterRegex: "CLI.*hpp" | |
| 78 | + | |
| 79 | +FormatStyle: file | |
| 80 | +# WarningsAsErrors: "*" | ... | ... |
.github/CONTRIBUTING.md
| ... | ... | @@ -26,9 +26,10 @@ complexity of CLI11 needlessly. |
| 26 | 26 | - Formatting should be done with pre-commit, otherwise the format check will not |
| 27 | 27 | pass. However, it is trivial to apply this to your PR, so don't worry about |
| 28 | 28 | this check. If you do want to run it, see below. |
| 29 | -- Everything must pass clang-tidy as well, run with `-DCLI11_CLANG_TIDY=ON` (if | |
| 30 | - you set `-DCLI11_CLANG_TIDY_OPTIONS="-fix"`, make sure you use a single | |
| 31 | - threaded build process, or just build one example target). | |
| 29 | +- Everything must pass clang-tidy as well, run with | |
| 30 | + `-DCMAKE_CXX_CLANG_TIDY="$(which clang-tidy)"` (if you set | |
| 31 | + `"$(which clang-tidy) -fix"`, make sure you use a single threaded build | |
| 32 | + process, or just build one example target). | |
| 32 | 33 | - Your changes must also conform to most of the |
| 33 | 34 | [Google C++ Style Guide](https://google.github.io/styleguide/cppguide.html) |
| 34 | 35 | rules checked by [cpplint](https://github.com/cpplint/cpplint). For unused | ... | ... |
.github/workflows/tests.yml
| ... | ... | @@ -7,6 +7,22 @@ on: |
| 7 | 7 | pull_request: |
| 8 | 8 | |
| 9 | 9 | jobs: |
| 10 | + clang-tidy: | |
| 11 | + name: Clang-Tidy | |
| 12 | + runs-on: ubuntu-latest | |
| 13 | + container: silkeh/clang:14 | |
| 14 | + steps: | |
| 15 | + - uses: actions/checkout@v3 | |
| 16 | + | |
| 17 | + - name: Configure | |
| 18 | + run: > | |
| 19 | + cmake -S . -B build -DCMAKE_CXX_STANDARD=17 | |
| 20 | + -DCMAKE_CXX_CLANG_TIDY="$(which | |
| 21 | + clang-tidy);--use-color;--warnings-as-errors=*" | |
| 22 | + | |
| 23 | + - name: Build | |
| 24 | + run: cmake --build build -j4 -- --keep-going | |
| 25 | + | |
| 10 | 26 | cuda-build: |
| 11 | 27 | name: CUDA build only |
| 12 | 28 | runs-on: ubuntu-latest | ... | ... |
CMakeLists.txt
| ... | ... | @@ -105,13 +105,6 @@ cmake_dependent_option( |
| 105 | 105 | CLI11_CUDA_TESTS "Build the tests with NVCC to check for warnings there - requires CMake 3.9+" |
| 106 | 106 | OFF "CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME" OFF) |
| 107 | 107 | |
| 108 | -cmake_dependent_option( | |
| 109 | - CLI11_CLANG_TIDY "Look for and use Clang-Tidy" OFF | |
| 110 | - "CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME;NOT CMAKE_VERSION VERSION_LESS 3.6" OFF) | |
| 111 | -set(CLI11_CLANG_TIDY_OPTIONS | |
| 112 | - "" | |
| 113 | - CACHE STRING "Clang tidy options, such as -fix, semicolon separated") | |
| 114 | - | |
| 115 | 108 | if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME AND NOT DEFINED CMAKE_CXX_STANDARD) |
| 116 | 109 | set(CMAKE_CXX_STANDARD 11) |
| 117 | 110 | endif() |
| ... | ... | @@ -134,6 +127,22 @@ add_library(CLI11_warnings INTERFACE) |
| 134 | 127 | |
| 135 | 128 | set(unix-warnings -Wall -Wextra -pedantic -Wshadow -Wsign-conversion -Wswitch-enum) |
| 136 | 129 | |
| 130 | +# Clang warnings | |
| 131 | +# -Wfloat-equal could be added with Catch::literals and _a usage | |
| 132 | +if(CMAKE_CXX_COMPILER_ID MATCHES "Clang") | |
| 133 | + list( | |
| 134 | + APPEND | |
| 135 | + unix-warnings | |
| 136 | + -Wcast-align | |
| 137 | + -Wimplicit-atomic-properties | |
| 138 | + -Wmissing-declarations | |
| 139 | + -Woverlength-strings | |
| 140 | + -Wshadow | |
| 141 | + -Wstrict-selector-match | |
| 142 | + -Wundeclared-selector) | |
| 143 | + # -Wunreachable-code Doesn't work on Clang 3.4 | |
| 144 | +endif() | |
| 145 | + | |
| 137 | 146 | # Buggy in GCC 4.8 |
| 138 | 147 | if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.9) |
| 139 | 148 | list(APPEND unix-warnings -Weffc++) |
| ... | ... | @@ -191,16 +200,6 @@ if(CLI11_CUDA_TESTS) |
| 191 | 200 | set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} -Xcudafe --display_error_number") |
| 192 | 201 | endif() |
| 193 | 202 | |
| 194 | -# Prepare Clang-Tidy | |
| 195 | -if(CLI11_CLANG_TIDY) | |
| 196 | - find_program( | |
| 197 | - CLANG_TIDY_EXE | |
| 198 | - NAMES "clang-tidy" | |
| 199 | - DOC "Path to clang-tidy executable" REQUIRED) | |
| 200 | - | |
| 201 | - set(DO_CLANG_TIDY "${CLANG_TIDY_EXE}" ${CLI11_CLANG_TIDY_OPTIONS}) | |
| 202 | -endif() | |
| 203 | - | |
| 204 | 203 | # This folder should be installed |
| 205 | 204 | if(CLI11_INSTALL) |
| 206 | 205 | install(DIRECTORY "${PROJECT_SOURCE_DIR}/include/" DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}") | ... | ... |
azure-pipelines.yml
| ... | ... | @@ -19,26 +19,6 @@ variables: |
| 19 | 19 | CMAKE_BUILD_PARALLEL_LEVEL: 4 |
| 20 | 20 | |
| 21 | 21 | jobs: |
| 22 | - - job: ClangTidy | |
| 23 | - variables: | |
| 24 | - CXX_FLAGS: > | |
| 25 | - -Werror -Wcast-align -Wfloat-equal -Wimplicit-atomic-properties | |
| 26 | - -Wmissing-declarations -Woverlength-strings -Wshadow | |
| 27 | - -Wstrict-selector-match -Wundeclared-selector -Wunreachable-code | |
| 28 | - -std=c++11 | |
| 29 | - cli11.options: -DCLI11_CLANG_TIDY=ON -DCLI11_CLANG_TIDY_OPTIONS="-fix" | |
| 30 | - cli11.std: 11 | |
| 31 | - cli11.single: OFF | |
| 32 | - CMAKE_BUILD_PARALLEL_LEVEL: 1 | |
| 33 | - pool: | |
| 34 | - vmImage: "ubuntu-latest" | |
| 35 | - container: silkeh/clang:8 | |
| 36 | - steps: | |
| 37 | - - template: .ci/azure-cmake.yml | |
| 38 | - - template: .ci/azure-build.yml | |
| 39 | - - script: git diff --exit-code --color | |
| 40 | - displayName: Check tidy | |
| 41 | - | |
| 42 | 22 | - job: CppLint |
| 43 | 23 | pool: |
| 44 | 24 | vmImage: "ubuntu-latest" | ... | ... |
examples/CMakeLists.txt
| ... | ... | @@ -8,9 +8,6 @@ function(add_cli_exe T) |
| 8 | 8 | APPEND_STRING |
| 9 | 9 | PROPERTY LINK_FLAGS -stdlib=libc++) |
| 10 | 10 | endif() |
| 11 | - if(CLI11_CLANG_TIDY) | |
| 12 | - set_property(TARGET ${T} PROPERTY CXX_CLANG_TIDY "${DO_CLANG_TIDY}") | |
| 13 | - endif() | |
| 14 | 11 | endfunction() |
| 15 | 12 | |
| 16 | 13 | if(CLI11_BUILD_EXAMPLES_JSON) | ... | ... |
examples/custom_parse.cpp
| ... | ... | @@ -22,7 +22,7 @@ template <class T = int> struct Values { |
| 22 | 22 | using DoubleValues = Values<double>; |
| 23 | 23 | |
| 24 | 24 | // the lexical cast operator should be in the same namespace as the type for ADL to work properly |
| 25 | -bool lexical_cast(const std::string &input, Values<double> &v) { | |
| 25 | +bool lexical_cast(const std::string &input, Values<double> & /*v*/) { | |
| 26 | 26 | std::cout << "called correct lexical_cast function ! val: " << input << std::endl; |
| 27 | 27 | return true; |
| 28 | 28 | } | ... | ... |
examples/formatter.cpp
| ... | ... | @@ -24,9 +24,9 @@ int main(int argc, char **argv) { |
| 24 | 24 | |
| 25 | 25 | app.add_flag("--flag", "This is a flag"); |
| 26 | 26 | |
| 27 | - auto sub1 = app.add_subcommand("one", "Description One"); | |
| 27 | + auto *sub1 = app.add_subcommand("one", "Description One"); | |
| 28 | 28 | sub1->add_flag("--oneflag", "Some flag"); |
| 29 | - auto sub2 = app.add_subcommand("two", "Description Two"); | |
| 29 | + auto *sub2 = app.add_subcommand("two", "Description Two"); | |
| 30 | 30 | sub2->add_flag("--twoflag", "Some other flag"); |
| 31 | 31 | |
| 32 | 32 | CLI11_PARSE(app, argc, argv); | ... | ... |
examples/groups.cpp
examples/inter_argument_order.cpp
| ... | ... | @@ -14,10 +14,10 @@ int main(int argc, char **argv) { |
| 14 | 14 | CLI::App app{"An app to practice mixing unlimited arguments, but still recover the original order."}; |
| 15 | 15 | |
| 16 | 16 | std::vector<int> foos; |
| 17 | - auto foo = app.add_option("--foo,-f", foos, "Some unlimited argument"); | |
| 17 | + auto *foo = app.add_option("--foo,-f", foos, "Some unlimited argument"); | |
| 18 | 18 | |
| 19 | 19 | std::vector<int> bars; |
| 20 | - auto bar = app.add_option("--bar", bars, "Some unlimited argument"); | |
| 20 | + auto *bar = app.add_option("--bar", bars, "Some unlimited argument"); | |
| 21 | 21 | |
| 22 | 22 | app.add_flag("--z,--x", "Random other flags"); |
| 23 | 23 | |
| ... | ... | @@ -33,7 +33,7 @@ int main(int argc, char **argv) { |
| 33 | 33 | std::reverse(std::begin(bars), std::end(bars)); |
| 34 | 34 | |
| 35 | 35 | std::vector<std::pair<std::string, int>> keyval; |
| 36 | - for(auto option : app.parse_order()) { | |
| 36 | + for(auto *option : app.parse_order()) { | |
| 37 | 37 | if(option == foo) { |
| 38 | 38 | keyval.emplace_back("foo", foos.back()); |
| 39 | 39 | foos.pop_back(); | ... | ... |
examples/modhelp.cpp
| ... | ... | @@ -16,7 +16,7 @@ Note that this will not shortcut `->required` and other similar options.)raw"}; |
| 16 | 16 | test.set_help_flag(); |
| 17 | 17 | |
| 18 | 18 | // Add custom flag that activates help |
| 19 | - auto help = test.add_flag("-h,--help", "Request help"); | |
| 19 | + auto *help = test.add_flag("-h,--help", "Request help"); | |
| 20 | 20 | |
| 21 | 21 | std::string some_option; |
| 22 | 22 | test.add_option("-a", some_option, "Some description"); | ... | ... |
examples/option_groups.cpp
| ... | ... | @@ -13,8 +13,8 @@ int main(int argc, char **argv) { |
| 13 | 13 | CLI::App app("data output specification"); |
| 14 | 14 | app.set_help_all_flag("--help-all", "Expand all help"); |
| 15 | 15 | |
| 16 | - auto format = app.add_option_group("output_format", "formatting type for output"); | |
| 17 | - auto target = app.add_option_group("output target", "target location for the output"); | |
| 16 | + auto *format = app.add_option_group("output_format", "formatting type for output"); | |
| 17 | + auto *target = app.add_option_group("output target", "target location for the output"); | |
| 18 | 18 | bool csv{false}; |
| 19 | 19 | bool human{false}; |
| 20 | 20 | bool binary{false}; | ... | ... |
examples/positional_arity.cpp
| ... | ... | @@ -12,8 +12,8 @@ int main(int argc, char **argv) { |
| 12 | 12 | |
| 13 | 13 | CLI::App app("test for positional arity"); |
| 14 | 14 | |
| 15 | - auto numbers = app.add_option_group("numbers", "specify key numbers"); | |
| 16 | - auto files = app.add_option_group("files", "specify files"); | |
| 15 | + auto *numbers = app.add_option_group("numbers", "specify key numbers"); | |
| 16 | + auto *files = app.add_option_group("files", "specify files"); | |
| 17 | 17 | int num1{-1}, num2{-1}; |
| 18 | 18 | numbers->add_option("num1", num1, "first number"); |
| 19 | 19 | numbers->add_option("num2", num2, "second number"); | ... | ... |
examples/prefix_command.cpp
examples/ranges.cpp
| ... | ... | @@ -15,7 +15,7 @@ int main(int argc, char **argv) { |
| 15 | 15 | std::vector<int> range; |
| 16 | 16 | app.add_option("--range,-R", range, "A range")->expected(-2); |
| 17 | 17 | |
| 18 | - auto ogroup = app.add_option_group("min_max_step", "set the min max and step"); | |
| 18 | + auto *ogroup = app.add_option_group("min_max_step", "set the min max and step"); | |
| 19 | 19 | int min{0}, max{0}, step{1}; |
| 20 | 20 | ogroup->add_option("--min,-m", min, "The minimum")->required(); |
| 21 | 21 | ogroup->add_option("--max,-M", max, "The maximum")->required(); | ... | ... |
examples/retired.cpp
| ... | ... | @@ -14,10 +14,10 @@ int main(int argc, char **argv) { |
| 14 | 14 | |
| 15 | 15 | CLI::App app("example for retired/deprecated options"); |
| 16 | 16 | std::vector<int> x; |
| 17 | - auto opt1 = app.add_option("--retired_option2", x); | |
| 17 | + auto *opt1 = app.add_option("--retired_option2", x); | |
| 18 | 18 | |
| 19 | 19 | std::pair<int, int> y; |
| 20 | - auto opt2 = app.add_option("--deprecate", y); | |
| 20 | + auto *opt2 = app.add_option("--deprecate", y); | |
| 21 | 21 | |
| 22 | 22 | app.add_option("--not_deprecated", x); |
| 23 | 23 | ... | ... |
examples/shapes.cpp
| ... | ... | @@ -13,7 +13,7 @@ int main(int argc, char **argv) { |
| 13 | 13 | CLI::App app("load shapes"); |
| 14 | 14 | |
| 15 | 15 | app.set_help_all_flag("--help-all"); |
| 16 | - auto circle = app.add_subcommand("circle", "draw a circle")->immediate_callback(); | |
| 16 | + auto *circle = app.add_subcommand("circle", "draw a circle")->immediate_callback(); | |
| 17 | 17 | double radius{0.0}; |
| 18 | 18 | int circle_counter{0}; |
| 19 | 19 | circle->callback([&radius, &circle_counter] { |
| ... | ... | @@ -23,7 +23,7 @@ int main(int argc, char **argv) { |
| 23 | 23 | |
| 24 | 24 | circle->add_option("radius", radius, "the radius of the circle")->required(); |
| 25 | 25 | |
| 26 | - auto rect = app.add_subcommand("rectangle", "draw a rectangle")->immediate_callback(); | |
| 26 | + auto *rect = app.add_subcommand("rectangle", "draw a rectangle")->immediate_callback(); | |
| 27 | 27 | double edge1{0.0}; |
| 28 | 28 | double edge2{0.0}; |
| 29 | 29 | int rect_counter{0}; |
| ... | ... | @@ -39,7 +39,7 @@ int main(int argc, char **argv) { |
| 39 | 39 | rect->add_option("edge1", edge1, "the first edge length of the rectangle")->required(); |
| 40 | 40 | rect->add_option("edge2", edge2, "the second edge length of the rectangle"); |
| 41 | 41 | |
| 42 | - auto tri = app.add_subcommand("triangle", "draw a rectangle")->immediate_callback(); | |
| 42 | + auto *tri = app.add_subcommand("triangle", "draw a rectangle")->immediate_callback(); | |
| 43 | 43 | std::vector<double> sides; |
| 44 | 44 | int tri_counter = 0; |
| 45 | 45 | tri->callback([&sides, &tri_counter] { | ... | ... |
examples/subcom_in_files/subcommand_a.cpp
| ... | ... | @@ -15,7 +15,7 @@ |
| 15 | 15 | void setup_subcommand_a(CLI::App &app) { |
| 16 | 16 | // Create the option and subcommand objects. |
| 17 | 17 | auto opt = std::make_shared<SubcommandAOptions>(); |
| 18 | - auto sub = app.add_subcommand("subcommand_a", "performs subcommand a"); | |
| 18 | + auto *sub = app.add_subcommand("subcommand_a", "performs subcommand a"); | |
| 19 | 19 | |
| 20 | 20 | // Add options to sub, binding them to opt. |
| 21 | 21 | sub->add_option("-f,--file", opt->file, "File name")->required(); | ... | ... |
examples/subcom_partitioned.cpp
examples/subcommands.cpp
| ... | ... | @@ -28,7 +28,7 @@ int main(int argc, char **argv) { |
| 28 | 28 | std::cout << "Working on --count from stop: " << s->count() << ", direct count: " << stop->count("--count") |
| 29 | 29 | << std::endl; |
| 30 | 30 | std::cout << "Count of --random flag: " << app.count("--random") << std::endl; |
| 31 | - for(auto subcom : app.get_subcommands()) | |
| 31 | + for(auto *subcom : app.get_subcommands()) | |
| 32 | 32 | std::cout << "Subcommand: " << subcom->get_name() << std::endl; |
| 33 | 33 | |
| 34 | 34 | return 0; | ... | ... |
examples/testEXE.cpp
| ... | ... | @@ -17,7 +17,7 @@ int main(int argc, const char *argv[]) { |
| 17 | 17 | |
| 18 | 18 | app.add_option("-v", logLevel, "level"); |
| 19 | 19 | |
| 20 | - auto subcom = app.add_subcommand("sub", "")->fallthrough(); | |
| 20 | + auto *subcom = app.add_subcommand("sub", "")->fallthrough(); | |
| 21 | 21 | subcom->preparse_callback([&app](size_t) { app.get_subcommand("sub")->add_option_group("group"); }); |
| 22 | 22 | |
| 23 | 23 | CLI11_PARSE(app, argc, argv); | ... | ... |
include/CLI/App.hpp
| ... | ... | @@ -374,7 +374,7 @@ class App { |
| 374 | 374 | if(parent_ != nullptr) { |
| 375 | 375 | auto oname = name_; |
| 376 | 376 | name_ = app_name; |
| 377 | - auto &res = _compare_subcommand_names(*this, *_get_fallthrough_parent()); | |
| 377 | + const auto &res = _compare_subcommand_names(*this, *_get_fallthrough_parent()); | |
| 378 | 378 | if(!res.empty()) { |
| 379 | 379 | name_ = oname; |
| 380 | 380 | throw(OptionAlreadyAdded(app_name + " conflicts with existing subcommand names")); |
| ... | ... | @@ -393,7 +393,7 @@ class App { |
| 393 | 393 | } |
| 394 | 394 | if(parent_ != nullptr) { |
| 395 | 395 | aliases_.push_back(app_name); |
| 396 | - auto &res = _compare_subcommand_names(*this, *_get_fallthrough_parent()); | |
| 396 | + const auto &res = _compare_subcommand_names(*this, *_get_fallthrough_parent()); | |
| 397 | 397 | if(!res.empty()) { |
| 398 | 398 | aliases_.pop_back(); |
| 399 | 399 | throw(OptionAlreadyAdded("alias already matches an existing subcommand: " + app_name)); |
| ... | ... | @@ -504,7 +504,7 @@ class App { |
| 504 | 504 | if(value && !ignore_case_) { |
| 505 | 505 | ignore_case_ = true; |
| 506 | 506 | auto *p = (parent_ != nullptr) ? _get_fallthrough_parent() : this; |
| 507 | - auto &match = _compare_subcommand_names(*this, *p); | |
| 507 | + const auto &match = _compare_subcommand_names(*this, *p); | |
| 508 | 508 | if(!match.empty()) { |
| 509 | 509 | ignore_case_ = false; // we are throwing so need to be exception invariant |
| 510 | 510 | throw OptionAlreadyAdded("ignore case would cause subcommand name conflicts: " + match); |
| ... | ... | @@ -538,7 +538,7 @@ class App { |
| 538 | 538 | if(value && !ignore_underscore_) { |
| 539 | 539 | ignore_underscore_ = true; |
| 540 | 540 | auto *p = (parent_ != nullptr) ? _get_fallthrough_parent() : this; |
| 541 | - auto &match = _compare_subcommand_names(*this, *p); | |
| 541 | + const auto &match = _compare_subcommand_names(*this, *p); | |
| 542 | 542 | if(!match.empty()) { |
| 543 | 543 | ignore_underscore_ = false; |
| 544 | 544 | throw OptionAlreadyAdded("ignore underscore would cause subcommand name conflicts: " + match); |
| ... | ... | @@ -567,7 +567,7 @@ class App { |
| 567 | 567 | } |
| 568 | 568 | |
| 569 | 569 | /// Check to see if this subcommand was parsed, true only if received on command line. |
| 570 | - bool parsed() const { return parsed_ > 0; } | |
| 570 | + CLI11_NODISCARD bool parsed() const { return parsed_ > 0; } | |
| 571 | 571 | |
| 572 | 572 | /// Get the OptionDefault object, to set option defaults |
| 573 | 573 | OptionDefaults *option_defaults() { return &option_defaults_; } |
| ... | ... | @@ -622,7 +622,7 @@ class App { |
| 622 | 622 | } |
| 623 | 623 | // we know something matches now find what it is so we can produce more error information |
| 624 | 624 | for(auto &opt : options_) { |
| 625 | - auto &matchname = opt->matching_name(myopt); | |
| 625 | + const auto &matchname = opt->matching_name(myopt); | |
| 626 | 626 | if(!matchname.empty()) { |
| 627 | 627 | throw(OptionAlreadyAdded("added option matched existing option name: " + matchname)); |
| 628 | 628 | } |
| ... | ... | @@ -785,7 +785,7 @@ class App { |
| 785 | 785 | private: |
| 786 | 786 | /// Internal function for adding a flag |
| 787 | 787 | Option *_add_flag_internal(std::string flag_name, CLI::callback_t fun, std::string flag_description) { |
| 788 | - Option *opt; | |
| 788 | + Option *opt = nullptr; | |
| 789 | 789 | if(detail::has_default_flag_values(flag_name)) { |
| 790 | 790 | // check for default values and if it has them |
| 791 | 791 | auto flag_defaults = detail::get_default_flag_values(flag_name); |
| ... | ... | @@ -956,7 +956,7 @@ class App { |
| 956 | 956 | throw IncorrectConstruction("option group names may not contain newlines or null characters"); |
| 957 | 957 | } |
| 958 | 958 | auto option_group = std::make_shared<T>(std::move(group_description), group_name, this); |
| 959 | - auto ptr = option_group.get(); | |
| 959 | + auto *ptr = option_group.get(); | |
| 960 | 960 | // move to App_p for overload resolution on older gcc versions |
| 961 | 961 | App_p app_ptr = std::dynamic_pointer_cast<App>(option_group); |
| 962 | 962 | add_subcommand(std::move(app_ptr)); |
| ... | ... | @@ -990,8 +990,8 @@ class App { |
| 990 | 990 | App *add_subcommand(CLI::App_p subcom) { |
| 991 | 991 | if(!subcom) |
| 992 | 992 | throw IncorrectConstruction("passed App is not valid"); |
| 993 | - auto ckapp = (name_.empty() && parent_ != nullptr) ? _get_fallthrough_parent() : this; | |
| 994 | - auto &mstrg = _compare_subcommand_names(*subcom, *ckapp); | |
| 993 | + auto *ckapp = (name_.empty() && parent_ != nullptr) ? _get_fallthrough_parent() : this; | |
| 994 | + const auto &mstrg = _compare_subcommand_names(*subcom, *ckapp); | |
| 995 | 995 | if(!mstrg.empty()) { |
| 996 | 996 | throw(OptionAlreadyAdded("subcommand name or alias matches existing subcommand: " + mstrg)); |
| 997 | 997 | } |
| ... | ... | @@ -1028,14 +1028,14 @@ class App { |
| 1028 | 1028 | } |
| 1029 | 1029 | |
| 1030 | 1030 | /// Check to see if a subcommand is part of this command (text version) |
| 1031 | - App *get_subcommand(std::string subcom) const { | |
| 1032 | - auto subc = _find_subcommand(subcom, false, false); | |
| 1031 | + CLI11_NODISCARD App *get_subcommand(std::string subcom) const { | |
| 1032 | + auto *subc = _find_subcommand(subcom, false, false); | |
| 1033 | 1033 | if(subc == nullptr) |
| 1034 | 1034 | throw OptionNotFound(subcom); |
| 1035 | 1035 | return subc; |
| 1036 | 1036 | } |
| 1037 | 1037 | /// Get a pointer to subcommand by index |
| 1038 | - App *get_subcommand(int index = 0) const { | |
| 1038 | + CLI11_NODISCARD App *get_subcommand(int index = 0) const { | |
| 1039 | 1039 | if(index >= 0) { |
| 1040 | 1040 | auto uindex = static_cast<unsigned>(index); |
| 1041 | 1041 | if(uindex < subcommands_.size()) |
| ... | ... | @@ -1055,7 +1055,7 @@ class App { |
| 1055 | 1055 | } |
| 1056 | 1056 | |
| 1057 | 1057 | /// Check to see if a subcommand is part of this command (text version) |
| 1058 | - CLI::App_p get_subcommand_ptr(std::string subcom) const { | |
| 1058 | + CLI11_NODISCARD CLI::App_p get_subcommand_ptr(std::string subcom) const { | |
| 1059 | 1059 | for(const App_p &subcomptr : subcommands_) |
| 1060 | 1060 | if(subcomptr->check_name(subcom)) |
| 1061 | 1061 | return subcomptr; |
| ... | ... | @@ -1063,7 +1063,7 @@ class App { |
| 1063 | 1063 | } |
| 1064 | 1064 | |
| 1065 | 1065 | /// Get an owning pointer to subcommand by index |
| 1066 | - CLI::App_p get_subcommand_ptr(int index = 0) const { | |
| 1066 | + CLI11_NODISCARD CLI::App_p get_subcommand_ptr(int index = 0) const { | |
| 1067 | 1067 | if(index >= 0) { |
| 1068 | 1068 | auto uindex = static_cast<unsigned>(index); |
| 1069 | 1069 | if(uindex < subcommands_.size()) |
| ... | ... | @@ -1073,7 +1073,7 @@ class App { |
| 1073 | 1073 | } |
| 1074 | 1074 | |
| 1075 | 1075 | /// Check to see if an option group is part of this App |
| 1076 | - App *get_option_group(std::string group_name) const { | |
| 1076 | + CLI11_NODISCARD App *get_option_group(std::string group_name) const { | |
| 1077 | 1077 | for(const App_p &app : subcommands_) { |
| 1078 | 1078 | if(app->name_.empty() && app->group_ == group_name) { |
| 1079 | 1079 | return app.get(); |
| ... | ... | @@ -1085,16 +1085,16 @@ class App { |
| 1085 | 1085 | /// No argument version of count counts the number of times this subcommand was |
| 1086 | 1086 | /// passed in. The main app will return 1. Unnamed subcommands will also return 1 unless |
| 1087 | 1087 | /// otherwise modified in a callback |
| 1088 | - std::size_t count() const { return parsed_; } | |
| 1088 | + CLI11_NODISCARD std::size_t count() const { return parsed_; } | |
| 1089 | 1089 | |
| 1090 | 1090 | /// Get a count of all the arguments processed in options and subcommands, this excludes arguments which were |
| 1091 | 1091 | /// treated as extras. |
| 1092 | - std::size_t count_all() const { | |
| 1092 | + CLI11_NODISCARD std::size_t count_all() const { | |
| 1093 | 1093 | std::size_t cnt{0}; |
| 1094 | - for(auto &opt : options_) { | |
| 1094 | + for(const auto &opt : options_) { | |
| 1095 | 1095 | cnt += opt->count(); |
| 1096 | 1096 | } |
| 1097 | - for(auto &sub : subcommands_) { | |
| 1097 | + for(const auto &sub : subcommands_) { | |
| 1098 | 1098 | cnt += sub->count_all(); |
| 1099 | 1099 | } |
| 1100 | 1100 | if(!get_name().empty()) { // for named subcommands add the number of times the subcommand was called |
| ... | ... | @@ -1345,11 +1345,11 @@ class App { |
| 1345 | 1345 | ///@{ |
| 1346 | 1346 | |
| 1347 | 1347 | /// Counts the number of times the given option was passed. |
| 1348 | - std::size_t count(std::string option_name) const { return get_option(option_name)->count(); } | |
| 1348 | + CLI11_NODISCARD std::size_t count(std::string option_name) const { return get_option(option_name)->count(); } | |
| 1349 | 1349 | |
| 1350 | 1350 | /// Get a subcommand pointer list to the currently selected subcommands (after parsing by default, in command |
| 1351 | 1351 | /// line order; use parsed = false to get the original definition list.) |
| 1352 | - std::vector<App *> get_subcommands() const { return parsed_subcommands_; } | |
| 1352 | + CLI11_NODISCARD std::vector<App *> get_subcommands() const { return parsed_subcommands_; } | |
| 1353 | 1353 | |
| 1354 | 1354 | /// Get a filtered subcommand pointer list from the original definition list. An empty function will provide all |
| 1355 | 1355 | /// subcommands (const) |
| ... | ... | @@ -1393,7 +1393,9 @@ class App { |
| 1393 | 1393 | } |
| 1394 | 1394 | |
| 1395 | 1395 | /// Check with name instead of pointer to see if subcommand was selected |
| 1396 | - bool got_subcommand(std::string subcommand_name) const { return get_subcommand(subcommand_name)->parsed_ > 0; } | |
| 1396 | + CLI11_NODISCARD bool got_subcommand(std::string subcommand_name) const { | |
| 1397 | + return get_subcommand(subcommand_name)->parsed_ > 0; | |
| 1398 | + } | |
| 1397 | 1399 | |
| 1398 | 1400 | /// Sets excluded options for the subcommand |
| 1399 | 1401 | App *excludes(Option *opt) { |
| ... | ... | @@ -1455,7 +1457,7 @@ class App { |
| 1455 | 1457 | if(iterator == std::end(exclude_subcommands_)) { |
| 1456 | 1458 | return false; |
| 1457 | 1459 | } |
| 1458 | - auto other_app = *iterator; | |
| 1460 | + auto *other_app = *iterator; | |
| 1459 | 1461 | exclude_subcommands_.erase(iterator); |
| 1460 | 1462 | other_app->remove_excludes(this); |
| 1461 | 1463 | return true; |
| ... | ... | @@ -1497,13 +1499,13 @@ class App { |
| 1497 | 1499 | } |
| 1498 | 1500 | /// Produce a string that could be read in as a config of the current values of the App. Set default_also to |
| 1499 | 1501 | /// include default arguments. write_descriptions will print a description for the App and for each option. |
| 1500 | - std::string config_to_str(bool default_also = false, bool write_description = false) const { | |
| 1502 | + CLI11_NODISCARD std::string config_to_str(bool default_also = false, bool write_description = false) const { | |
| 1501 | 1503 | return config_formatter_->to_config(this, default_also, write_description, ""); |
| 1502 | 1504 | } |
| 1503 | 1505 | |
| 1504 | 1506 | /// Makes a help message, using the currently configured formatter |
| 1505 | 1507 | /// Will only do one subcommand at a time |
| 1506 | - std::string help(std::string prev = "", AppFormatMode mode = AppFormatMode::Normal) const { | |
| 1508 | + CLI11_NODISCARD std::string help(std::string prev = "", AppFormatMode mode = AppFormatMode::Normal) const { | |
| 1507 | 1509 | if(prev.empty()) |
| 1508 | 1510 | prev = get_name(); |
| 1509 | 1511 | else |
| ... | ... | @@ -1518,7 +1520,7 @@ class App { |
| 1518 | 1520 | } |
| 1519 | 1521 | |
| 1520 | 1522 | /// Displays a version string |
| 1521 | - std::string version() const { | |
| 1523 | + CLI11_NODISCARD std::string version() const { | |
| 1522 | 1524 | std::string val; |
| 1523 | 1525 | if(version_ptr_ != nullptr) { |
| 1524 | 1526 | auto rv = version_ptr_->results(); |
| ... | ... | @@ -1539,13 +1541,13 @@ class App { |
| 1539 | 1541 | ///@{ |
| 1540 | 1542 | |
| 1541 | 1543 | /// Access the formatter |
| 1542 | - std::shared_ptr<FormatterBase> get_formatter() const { return formatter_; } | |
| 1544 | + CLI11_NODISCARD std::shared_ptr<FormatterBase> get_formatter() const { return formatter_; } | |
| 1543 | 1545 | |
| 1544 | 1546 | /// Access the config formatter |
| 1545 | - std::shared_ptr<Config> get_config_formatter() const { return config_formatter_; } | |
| 1547 | + CLI11_NODISCARD std::shared_ptr<Config> get_config_formatter() const { return config_formatter_; } | |
| 1546 | 1548 | |
| 1547 | 1549 | /// Access the config formatter as a configBase pointer |
| 1548 | - std::shared_ptr<ConfigBase> get_config_formatter_base() const { | |
| 1550 | + CLI11_NODISCARD std::shared_ptr<ConfigBase> get_config_formatter_base() const { | |
| 1549 | 1551 | // This is safer as a dynamic_cast if we have RTTI, as Config -> ConfigBase |
| 1550 | 1552 | #if CLI11_USE_STATIC_RTTI == 0 |
| 1551 | 1553 | return std::dynamic_pointer_cast<ConfigBase>(config_formatter_); |
| ... | ... | @@ -1555,7 +1557,7 @@ class App { |
| 1555 | 1557 | } |
| 1556 | 1558 | |
| 1557 | 1559 | /// Get the app or subcommand description |
| 1558 | - std::string get_description() const { return description_; } | |
| 1560 | + CLI11_NODISCARD std::string get_description() const { return description_; } | |
| 1559 | 1561 | |
| 1560 | 1562 | /// Set the description of the app |
| 1561 | 1563 | App *description(std::string app_description) { |
| ... | ... | @@ -1606,7 +1608,7 @@ class App { |
| 1606 | 1608 | for(auto &subc : subcommands_) { |
| 1607 | 1609 | // also check down into nameless subcommands |
| 1608 | 1610 | if(subc->get_name().empty()) { |
| 1609 | - auto opt = subc->get_option_no_throw(option_name); | |
| 1611 | + auto *opt = subc->get_option_no_throw(option_name); | |
| 1610 | 1612 | if(opt != nullptr) { |
| 1611 | 1613 | return opt; |
| 1612 | 1614 | } |
| ... | ... | @@ -1616,7 +1618,7 @@ class App { |
| 1616 | 1618 | } |
| 1617 | 1619 | |
| 1618 | 1620 | /// Get an option by name (noexcept const version) |
| 1619 | - const Option *get_option_no_throw(std::string option_name) const noexcept { | |
| 1621 | + CLI11_NODISCARD const Option *get_option_no_throw(std::string option_name) const noexcept { | |
| 1620 | 1622 | for(const Option_p &opt : options_) { |
| 1621 | 1623 | if(opt->check_name(option_name)) { |
| 1622 | 1624 | return opt.get(); |
| ... | ... | @@ -1625,7 +1627,7 @@ class App { |
| 1625 | 1627 | for(const auto &subc : subcommands_) { |
| 1626 | 1628 | // also check down into nameless subcommands |
| 1627 | 1629 | if(subc->get_name().empty()) { |
| 1628 | - auto opt = subc->get_option_no_throw(option_name); | |
| 1630 | + auto *opt = subc->get_option_no_throw(option_name); | |
| 1629 | 1631 | if(opt != nullptr) { |
| 1630 | 1632 | return opt; |
| 1631 | 1633 | } |
| ... | ... | @@ -1635,8 +1637,8 @@ class App { |
| 1635 | 1637 | } |
| 1636 | 1638 | |
| 1637 | 1639 | /// Get an option by name |
| 1638 | - const Option *get_option(std::string option_name) const { | |
| 1639 | - auto opt = get_option_no_throw(option_name); | |
| 1640 | + CLI11_NODISCARD const Option *get_option(std::string option_name) const { | |
| 1641 | + const auto *opt = get_option_no_throw(option_name); | |
| 1640 | 1642 | if(opt == nullptr) { |
| 1641 | 1643 | throw OptionNotFound(option_name); |
| 1642 | 1644 | } |
| ... | ... | @@ -1645,7 +1647,7 @@ class App { |
| 1645 | 1647 | |
| 1646 | 1648 | /// Get an option by name (non-const version) |
| 1647 | 1649 | Option *get_option(std::string option_name) { |
| 1648 | - auto opt = get_option_no_throw(option_name); | |
| 1650 | + auto *opt = get_option_no_throw(option_name); | |
| 1649 | 1651 | if(opt == nullptr) { |
| 1650 | 1652 | throw OptionNotFound(option_name); |
| 1651 | 1653 | } |
| ... | ... | @@ -1659,104 +1661,106 @@ class App { |
| 1659 | 1661 | const Option *operator[](const char *option_name) const { return get_option(option_name); } |
| 1660 | 1662 | |
| 1661 | 1663 | /// Check the status of ignore_case |
| 1662 | - bool get_ignore_case() const { return ignore_case_; } | |
| 1664 | + CLI11_NODISCARD bool get_ignore_case() const { return ignore_case_; } | |
| 1663 | 1665 | |
| 1664 | 1666 | /// Check the status of ignore_underscore |
| 1665 | - bool get_ignore_underscore() const { return ignore_underscore_; } | |
| 1667 | + CLI11_NODISCARD bool get_ignore_underscore() const { return ignore_underscore_; } | |
| 1666 | 1668 | |
| 1667 | 1669 | /// Check the status of fallthrough |
| 1668 | - bool get_fallthrough() const { return fallthrough_; } | |
| 1670 | + CLI11_NODISCARD bool get_fallthrough() const { return fallthrough_; } | |
| 1669 | 1671 | |
| 1670 | 1672 | /// Check the status of the allow windows style options |
| 1671 | - bool get_allow_windows_style_options() const { return allow_windows_style_options_; } | |
| 1673 | + CLI11_NODISCARD bool get_allow_windows_style_options() const { return allow_windows_style_options_; } | |
| 1672 | 1674 | |
| 1673 | 1675 | /// Check the status of the allow windows style options |
| 1674 | - bool get_positionals_at_end() const { return positionals_at_end_; } | |
| 1676 | + CLI11_NODISCARD bool get_positionals_at_end() const { return positionals_at_end_; } | |
| 1675 | 1677 | |
| 1676 | 1678 | /// Check the status of the allow windows style options |
| 1677 | - bool get_configurable() const { return configurable_; } | |
| 1679 | + CLI11_NODISCARD bool get_configurable() const { return configurable_; } | |
| 1678 | 1680 | |
| 1679 | 1681 | /// Get the group of this subcommand |
| 1680 | - const std::string &get_group() const { return group_; } | |
| 1682 | + CLI11_NODISCARD const std::string &get_group() const { return group_; } | |
| 1681 | 1683 | |
| 1682 | 1684 | /// Generate and return the footer. |
| 1683 | - std::string get_footer() const { return (footer_callback_) ? footer_callback_() + '\n' + footer_ : footer_; } | |
| 1685 | + CLI11_NODISCARD std::string get_footer() const { | |
| 1686 | + return (footer_callback_) ? footer_callback_() + '\n' + footer_ : footer_; | |
| 1687 | + } | |
| 1684 | 1688 | |
| 1685 | 1689 | /// Get the required min subcommand value |
| 1686 | - std::size_t get_require_subcommand_min() const { return require_subcommand_min_; } | |
| 1690 | + CLI11_NODISCARD std::size_t get_require_subcommand_min() const { return require_subcommand_min_; } | |
| 1687 | 1691 | |
| 1688 | 1692 | /// Get the required max subcommand value |
| 1689 | - std::size_t get_require_subcommand_max() const { return require_subcommand_max_; } | |
| 1693 | + CLI11_NODISCARD std::size_t get_require_subcommand_max() const { return require_subcommand_max_; } | |
| 1690 | 1694 | |
| 1691 | 1695 | /// Get the required min option value |
| 1692 | - std::size_t get_require_option_min() const { return require_option_min_; } | |
| 1696 | + CLI11_NODISCARD std::size_t get_require_option_min() const { return require_option_min_; } | |
| 1693 | 1697 | |
| 1694 | 1698 | /// Get the required max option value |
| 1695 | - std::size_t get_require_option_max() const { return require_option_max_; } | |
| 1699 | + CLI11_NODISCARD std::size_t get_require_option_max() const { return require_option_max_; } | |
| 1696 | 1700 | |
| 1697 | 1701 | /// Get the prefix command status |
| 1698 | - bool get_prefix_command() const { return prefix_command_; } | |
| 1702 | + CLI11_NODISCARD bool get_prefix_command() const { return prefix_command_; } | |
| 1699 | 1703 | |
| 1700 | 1704 | /// Get the status of allow extras |
| 1701 | - bool get_allow_extras() const { return allow_extras_; } | |
| 1705 | + CLI11_NODISCARD bool get_allow_extras() const { return allow_extras_; } | |
| 1702 | 1706 | |
| 1703 | 1707 | /// Get the status of required |
| 1704 | - bool get_required() const { return required_; } | |
| 1708 | + CLI11_NODISCARD bool get_required() const { return required_; } | |
| 1705 | 1709 | |
| 1706 | 1710 | /// Get the status of disabled |
| 1707 | - bool get_disabled() const { return disabled_; } | |
| 1711 | + CLI11_NODISCARD bool get_disabled() const { return disabled_; } | |
| 1708 | 1712 | |
| 1709 | 1713 | /// Get the status of silence |
| 1710 | - bool get_silent() const { return silent_; } | |
| 1714 | + CLI11_NODISCARD bool get_silent() const { return silent_; } | |
| 1711 | 1715 | |
| 1712 | 1716 | /// Get the status of disabled |
| 1713 | - bool get_immediate_callback() const { return immediate_callback_; } | |
| 1717 | + CLI11_NODISCARD bool get_immediate_callback() const { return immediate_callback_; } | |
| 1714 | 1718 | |
| 1715 | 1719 | /// Get the status of disabled by default |
| 1716 | - bool get_disabled_by_default() const { return (default_startup == startup_mode::disabled); } | |
| 1720 | + CLI11_NODISCARD bool get_disabled_by_default() const { return (default_startup == startup_mode::disabled); } | |
| 1717 | 1721 | |
| 1718 | 1722 | /// Get the status of disabled by default |
| 1719 | - bool get_enabled_by_default() const { return (default_startup == startup_mode::enabled); } | |
| 1723 | + CLI11_NODISCARD bool get_enabled_by_default() const { return (default_startup == startup_mode::enabled); } | |
| 1720 | 1724 | /// Get the status of validating positionals |
| 1721 | - bool get_validate_positionals() const { return validate_positionals_; } | |
| 1725 | + CLI11_NODISCARD bool get_validate_positionals() const { return validate_positionals_; } | |
| 1722 | 1726 | /// Get the status of validating optional vector arguments |
| 1723 | - bool get_validate_optional_arguments() const { return validate_optional_arguments_; } | |
| 1727 | + CLI11_NODISCARD bool get_validate_optional_arguments() const { return validate_optional_arguments_; } | |
| 1724 | 1728 | |
| 1725 | 1729 | /// Get the status of allow extras |
| 1726 | - config_extras_mode get_allow_config_extras() const { return allow_config_extras_; } | |
| 1730 | + CLI11_NODISCARD config_extras_mode get_allow_config_extras() const { return allow_config_extras_; } | |
| 1727 | 1731 | |
| 1728 | 1732 | /// Get a pointer to the help flag. |
| 1729 | 1733 | Option *get_help_ptr() { return help_ptr_; } |
| 1730 | 1734 | |
| 1731 | 1735 | /// Get a pointer to the help flag. (const) |
| 1732 | - const Option *get_help_ptr() const { return help_ptr_; } | |
| 1736 | + CLI11_NODISCARD const Option *get_help_ptr() const { return help_ptr_; } | |
| 1733 | 1737 | |
| 1734 | 1738 | /// Get a pointer to the help all flag. (const) |
| 1735 | - const Option *get_help_all_ptr() const { return help_all_ptr_; } | |
| 1739 | + CLI11_NODISCARD const Option *get_help_all_ptr() const { return help_all_ptr_; } | |
| 1736 | 1740 | |
| 1737 | 1741 | /// Get a pointer to the config option. |
| 1738 | 1742 | Option *get_config_ptr() { return config_ptr_; } |
| 1739 | 1743 | |
| 1740 | 1744 | /// Get a pointer to the config option. (const) |
| 1741 | - const Option *get_config_ptr() const { return config_ptr_; } | |
| 1745 | + CLI11_NODISCARD const Option *get_config_ptr() const { return config_ptr_; } | |
| 1742 | 1746 | |
| 1743 | 1747 | /// Get a pointer to the version option. |
| 1744 | 1748 | Option *get_version_ptr() { return version_ptr_; } |
| 1745 | 1749 | |
| 1746 | 1750 | /// Get a pointer to the version option. (const) |
| 1747 | - const Option *get_version_ptr() const { return version_ptr_; } | |
| 1751 | + CLI11_NODISCARD const Option *get_version_ptr() const { return version_ptr_; } | |
| 1748 | 1752 | |
| 1749 | 1753 | /// Get the parent of this subcommand (or nullptr if main app) |
| 1750 | 1754 | App *get_parent() { return parent_; } |
| 1751 | 1755 | |
| 1752 | 1756 | /// Get the parent of this subcommand (or nullptr if main app) (const version) |
| 1753 | - const App *get_parent() const { return parent_; } | |
| 1757 | + CLI11_NODISCARD const App *get_parent() const { return parent_; } | |
| 1754 | 1758 | |
| 1755 | 1759 | /// Get the name of the current app |
| 1756 | - const std::string &get_name() const { return name_; } | |
| 1760 | + CLI11_NODISCARD const std::string &get_name() const { return name_; } | |
| 1757 | 1761 | |
| 1758 | 1762 | /// Get the aliases of the current app |
| 1759 | - const std::vector<std::string> &get_aliases() const { return aliases_; } | |
| 1763 | + CLI11_NODISCARD const std::vector<std::string> &get_aliases() const { return aliases_; } | |
| 1760 | 1764 | |
| 1761 | 1765 | /// clear all the aliases of the current App |
| 1762 | 1766 | App *clear_aliases() { |
| ... | ... | @@ -1765,7 +1769,7 @@ class App { |
| 1765 | 1769 | } |
| 1766 | 1770 | |
| 1767 | 1771 | /// Get a display name for an app |
| 1768 | - std::string get_display_name(bool with_aliases = false) const { | |
| 1772 | + CLI11_NODISCARD std::string get_display_name(bool with_aliases = false) const { | |
| 1769 | 1773 | if(name_.empty()) { |
| 1770 | 1774 | return std::string("[Option Group: ") + get_group() + "]"; |
| 1771 | 1775 | } |
| ... | ... | @@ -1782,7 +1786,7 @@ class App { |
| 1782 | 1786 | } |
| 1783 | 1787 | |
| 1784 | 1788 | /// Check the name, case insensitive and underscore insensitive if set |
| 1785 | - bool check_name(std::string name_to_check) const { | |
| 1789 | + CLI11_NODISCARD bool check_name(std::string name_to_check) const { | |
| 1786 | 1790 | std::string local_name = name_; |
| 1787 | 1791 | if(ignore_underscore_) { |
| 1788 | 1792 | local_name = detail::remove_underscore(name_); |
| ... | ... | @@ -1796,7 +1800,7 @@ class App { |
| 1796 | 1800 | if(local_name == name_to_check) { |
| 1797 | 1801 | return true; |
| 1798 | 1802 | } |
| 1799 | - for(auto les : aliases_) { | |
| 1803 | + for(auto les : aliases_) { // NOLINT(performance-for-range-copy) | |
| 1800 | 1804 | if(ignore_underscore_) { |
| 1801 | 1805 | les = detail::remove_underscore(les); |
| 1802 | 1806 | } |
| ... | ... | @@ -1811,7 +1815,7 @@ class App { |
| 1811 | 1815 | } |
| 1812 | 1816 | |
| 1813 | 1817 | /// Get the groups available directly from this option (in order) |
| 1814 | - std::vector<std::string> get_groups() const { | |
| 1818 | + CLI11_NODISCARD std::vector<std::string> get_groups() const { | |
| 1815 | 1819 | std::vector<std::string> groups; |
| 1816 | 1820 | |
| 1817 | 1821 | for(const Option_p &opt : options_) { |
| ... | ... | @@ -1825,10 +1829,10 @@ class App { |
| 1825 | 1829 | } |
| 1826 | 1830 | |
| 1827 | 1831 | /// This gets a vector of pointers with the original parse order |
| 1828 | - const std::vector<Option *> &parse_order() const { return parse_order_; } | |
| 1832 | + CLI11_NODISCARD const std::vector<Option *> &parse_order() const { return parse_order_; } | |
| 1829 | 1833 | |
| 1830 | 1834 | /// This returns the missing options from the current subcommand |
| 1831 | - std::vector<std::string> remaining(bool recurse = false) const { | |
| 1835 | + CLI11_NODISCARD std::vector<std::string> remaining(bool recurse = false) const { | |
| 1832 | 1836 | std::vector<std::string> miss_list; |
| 1833 | 1837 | for(const std::pair<detail::Classifier, std::string> &miss : missing_) { |
| 1834 | 1838 | miss_list.push_back(std::get<1>(miss)); |
| ... | ... | @@ -1855,14 +1859,14 @@ class App { |
| 1855 | 1859 | } |
| 1856 | 1860 | |
| 1857 | 1861 | /// This returns the missing options in a form ready for processing by another command line program |
| 1858 | - std::vector<std::string> remaining_for_passthrough(bool recurse = false) const { | |
| 1862 | + CLI11_NODISCARD std::vector<std::string> remaining_for_passthrough(bool recurse = false) const { | |
| 1859 | 1863 | std::vector<std::string> miss_list = remaining(recurse); |
| 1860 | 1864 | std::reverse(std::begin(miss_list), std::end(miss_list)); |
| 1861 | 1865 | return miss_list; |
| 1862 | 1866 | } |
| 1863 | 1867 | |
| 1864 | 1868 | /// This returns the number of remaining options, minus the -- separator |
| 1865 | - std::size_t remaining_size(bool recurse = false) const { | |
| 1869 | + CLI11_NODISCARD std::size_t remaining_size(bool recurse = false) const { | |
| 1866 | 1870 | auto remaining_options = static_cast<std::size_t>(std::count_if( |
| 1867 | 1871 | std::begin(missing_), std::end(missing_), [](const std::pair<detail::Classifier, std::string> &val) { |
| 1868 | 1872 | return val.first != detail::Classifier::POSITIONAL_MARK; |
| ... | ... | @@ -1971,12 +1975,12 @@ class App { |
| 1971 | 1975 | } |
| 1972 | 1976 | |
| 1973 | 1977 | /// Check to see if a subcommand is valid. Give up immediately if subcommand max has been reached. |
| 1974 | - bool _valid_subcommand(const std::string ¤t, bool ignore_used = true) const { | |
| 1978 | + CLI11_NODISCARD bool _valid_subcommand(const std::string ¤t, bool ignore_used = true) const { | |
| 1975 | 1979 | // Don't match if max has been reached - but still check parents |
| 1976 | 1980 | if(require_subcommand_max_ != 0 && parsed_subcommands_.size() >= require_subcommand_max_) { |
| 1977 | 1981 | return parent_ != nullptr && parent_->_valid_subcommand(current, ignore_used); |
| 1978 | 1982 | } |
| 1979 | - auto com = _find_subcommand(current, true, ignore_used); | |
| 1983 | + auto *com = _find_subcommand(current, true, ignore_used); | |
| 1980 | 1984 | if(com != nullptr) { |
| 1981 | 1985 | return true; |
| 1982 | 1986 | } |
| ... | ... | @@ -1985,7 +1989,8 @@ class App { |
| 1985 | 1989 | } |
| 1986 | 1990 | |
| 1987 | 1991 | /// Selects a Classifier enum based on the type of the current argument |
| 1988 | - detail::Classifier _recognize(const std::string ¤t, bool ignore_used_subcommands = true) const { | |
| 1992 | + CLI11_NODISCARD detail::Classifier _recognize(const std::string ¤t, | |
| 1993 | + bool ignore_used_subcommands = true) const { | |
| 1989 | 1994 | std::string dummy1, dummy2; |
| 1990 | 1995 | |
| 1991 | 1996 | if(current == "--") |
| ... | ... | @@ -2132,13 +2137,13 @@ class App { |
| 2132 | 2137 | // check excludes |
| 2133 | 2138 | bool excluded{false}; |
| 2134 | 2139 | std::string excluder; |
| 2135 | - for(auto &opt : exclude_options_) { | |
| 2140 | + for(const auto &opt : exclude_options_) { | |
| 2136 | 2141 | if(opt->count() > 0) { |
| 2137 | 2142 | excluded = true; |
| 2138 | 2143 | excluder = opt->get_name(); |
| 2139 | 2144 | } |
| 2140 | 2145 | } |
| 2141 | - for(auto &subc : exclude_subcommands_) { | |
| 2146 | + for(const auto &subc : exclude_subcommands_) { | |
| 2142 | 2147 | if(subc->count_all() > 0) { |
| 2143 | 2148 | excluded = true; |
| 2144 | 2149 | excluder = subc->get_display_name(); |
| ... | ... | @@ -2155,13 +2160,13 @@ class App { |
| 2155 | 2160 | // check excludes |
| 2156 | 2161 | bool missing_needed{false}; |
| 2157 | 2162 | std::string missing_need; |
| 2158 | - for(auto &opt : need_options_) { | |
| 2163 | + for(const auto &opt : need_options_) { | |
| 2159 | 2164 | if(opt->count() == 0) { |
| 2160 | 2165 | missing_needed = true; |
| 2161 | 2166 | missing_need = opt->get_name(); |
| 2162 | 2167 | } |
| 2163 | 2168 | } |
| 2164 | - for(auto &subc : need_subcommands_) { | |
| 2169 | + for(const auto &subc : need_subcommands_) { | |
| 2165 | 2170 | if(subc->count_all() == 0) { |
| 2166 | 2171 | missing_needed = true; |
| 2167 | 2172 | missing_need = subc->get_display_name(); |
| ... | ... | @@ -2392,7 +2397,7 @@ class App { |
| 2392 | 2397 | bool _parse_single_config(const ConfigItem &item, std::size_t level = 0) { |
| 2393 | 2398 | if(level < item.parents.size()) { |
| 2394 | 2399 | try { |
| 2395 | - auto subcom = get_subcommand(item.parents.at(level)); | |
| 2400 | + auto *subcom = get_subcommand(item.parents.at(level)); | |
| 2396 | 2401 | auto result = subcom->_parse_single_config(item, level + 1); |
| 2397 | 2402 | |
| 2398 | 2403 | return result; |
| ... | ... | @@ -2507,7 +2512,7 @@ class App { |
| 2507 | 2512 | } |
| 2508 | 2513 | |
| 2509 | 2514 | /// Count the required remaining positional arguments |
| 2510 | - std::size_t _count_remaining_positionals(bool required_only = false) const { | |
| 2515 | + CLI11_NODISCARD std::size_t _count_remaining_positionals(bool required_only = false) const { | |
| 2511 | 2516 | std::size_t retval = 0; |
| 2512 | 2517 | for(const Option_p &opt : options_) { |
| 2513 | 2518 | if(opt->get_positional() && (!required_only || opt->get_required())) { |
| ... | ... | @@ -2521,7 +2526,7 @@ class App { |
| 2521 | 2526 | } |
| 2522 | 2527 | |
| 2523 | 2528 | /// Count the required remaining positional arguments |
| 2524 | - bool _has_remaining_positionals() const { | |
| 2529 | + CLI11_NODISCARD bool _has_remaining_positionals() const { | |
| 2525 | 2530 | for(const Option_p &opt : options_) { |
| 2526 | 2531 | if(opt->get_positional() && ((static_cast<int>(opt->count()) < opt->get_items_expected_min()))) { |
| 2527 | 2532 | return true; |
| ... | ... | @@ -2620,7 +2625,7 @@ class App { |
| 2620 | 2625 | return _get_fallthrough_parent()->_parse_positional(args, static_cast<bool>(parse_complete_callback_)); |
| 2621 | 2626 | |
| 2622 | 2627 | /// Try to find a local subcommand that is repeated |
| 2623 | - auto com = _find_subcommand(args.back(), true, false); | |
| 2628 | + auto *com = _find_subcommand(args.back(), true, false); | |
| 2624 | 2629 | if(com != nullptr && (require_subcommand_max_ == 0 || require_subcommand_max_ > parsed_subcommands_.size())) { |
| 2625 | 2630 | if(haltOnSubcommand) { |
| 2626 | 2631 | return false; |
| ... | ... | @@ -2631,7 +2636,7 @@ class App { |
| 2631 | 2636 | } |
| 2632 | 2637 | /// now try one last gasp at subcommands that have been executed before, go to root app and try to find a |
| 2633 | 2638 | /// subcommand in a broader way, if one exists let the parent deal with it |
| 2634 | - auto parent_app = (parent_ != nullptr) ? _get_fallthrough_parent() : this; | |
| 2639 | + auto *parent_app = (parent_ != nullptr) ? _get_fallthrough_parent() : this; | |
| 2635 | 2640 | com = parent_app->_find_subcommand(args.back(), true, false); |
| 2636 | 2641 | if(com != nullptr && (com->parent_->require_subcommand_max_ == 0 || |
| 2637 | 2642 | com->parent_->require_subcommand_max_ > com->parent_->parsed_subcommands_.size())) { |
| ... | ... | @@ -2660,12 +2665,13 @@ class App { |
| 2660 | 2665 | |
| 2661 | 2666 | /// Locate a subcommand by name with two conditions, should disabled subcommands be ignored, and should used |
| 2662 | 2667 | /// subcommands be ignored |
| 2663 | - App *_find_subcommand(const std::string &subc_name, bool ignore_disabled, bool ignore_used) const noexcept { | |
| 2668 | + CLI11_NODISCARD App * | |
| 2669 | + _find_subcommand(const std::string &subc_name, bool ignore_disabled, bool ignore_used) const noexcept { | |
| 2664 | 2670 | for(const App_p &com : subcommands_) { |
| 2665 | 2671 | if(com->disabled_ && ignore_disabled) |
| 2666 | 2672 | continue; |
| 2667 | 2673 | if(com->get_name().empty()) { |
| 2668 | - auto subc = com->_find_subcommand(subc_name, ignore_disabled, ignore_used); | |
| 2674 | + auto *subc = com->_find_subcommand(subc_name, ignore_disabled, ignore_used); | |
| 2669 | 2675 | if(subc != nullptr) { |
| 2670 | 2676 | return subc; |
| 2671 | 2677 | } |
| ... | ... | @@ -2687,14 +2693,14 @@ class App { |
| 2687 | 2693 | _parse_positional(args, false); |
| 2688 | 2694 | return true; |
| 2689 | 2695 | } |
| 2690 | - auto com = _find_subcommand(args.back(), true, true); | |
| 2696 | + auto *com = _find_subcommand(args.back(), true, true); | |
| 2691 | 2697 | if(com != nullptr) { |
| 2692 | 2698 | args.pop_back(); |
| 2693 | 2699 | if(!com->silent_) { |
| 2694 | 2700 | parsed_subcommands_.push_back(com); |
| 2695 | 2701 | } |
| 2696 | 2702 | com->_parse(args); |
| 2697 | - auto parent_app = com->parent_; | |
| 2703 | + auto *parent_app = com->parent_; | |
| 2698 | 2704 | while(parent_app != this) { |
| 2699 | 2705 | parent_app->_trigger_pre_parse(args.size()); |
| 2700 | 2706 | if(!com->silent_) { |
| ... | ... | @@ -2908,7 +2914,7 @@ class App { |
| 2908 | 2914 | if(parent_ == nullptr) { |
| 2909 | 2915 | throw(HorribleError("No Valid parent")); |
| 2910 | 2916 | } |
| 2911 | - auto fallthrough_parent = parent_; | |
| 2917 | + auto *fallthrough_parent = parent_; | |
| 2912 | 2918 | while((fallthrough_parent->parent_ != nullptr) && (fallthrough_parent->get_name().empty())) { |
| 2913 | 2919 | fallthrough_parent = fallthrough_parent->parent_; |
| 2914 | 2920 | } |
| ... | ... | @@ -2916,12 +2922,12 @@ class App { |
| 2916 | 2922 | } |
| 2917 | 2923 | |
| 2918 | 2924 | /// Helper function to run through all possible comparisons of subcommand names to check there is no overlap |
| 2919 | - const std::string &_compare_subcommand_names(const App &subcom, const App &base) const { | |
| 2925 | + CLI11_NODISCARD const std::string &_compare_subcommand_names(const App &subcom, const App &base) const { | |
| 2920 | 2926 | static const std::string estring; |
| 2921 | 2927 | if(subcom.disabled_) { |
| 2922 | 2928 | return estring; |
| 2923 | 2929 | } |
| 2924 | - for(auto &subc : base.subcommands_) { | |
| 2930 | + for(const auto &subc : base.subcommands_) { | |
| 2925 | 2931 | if(subc.get() != &subcom) { |
| 2926 | 2932 | if(subc->disabled_) { |
| 2927 | 2933 | continue; |
| ... | ... | @@ -2949,14 +2955,14 @@ class App { |
| 2949 | 2955 | } |
| 2950 | 2956 | // if the subcommand is an option group we need to check deeper |
| 2951 | 2957 | if(subc->get_name().empty()) { |
| 2952 | - auto &cmpres = _compare_subcommand_names(subcom, *subc); | |
| 2958 | + const auto &cmpres = _compare_subcommand_names(subcom, *subc); | |
| 2953 | 2959 | if(!cmpres.empty()) { |
| 2954 | 2960 | return cmpres; |
| 2955 | 2961 | } |
| 2956 | 2962 | } |
| 2957 | 2963 | // if the test subcommand is an option group we need to check deeper |
| 2958 | 2964 | if(subcom.get_name().empty()) { |
| 2959 | - auto &cmpres = _compare_subcommand_names(*subc, subcom); | |
| 2965 | + const auto &cmpres = _compare_subcommand_names(*subc, subcom); | |
| 2960 | 2966 | if(!cmpres.empty()) { |
| 2961 | 2967 | return cmpres; |
| 2962 | 2968 | } |
| ... | ... | @@ -3072,7 +3078,7 @@ inline void TriggerOn(App *trigger_app, std::vector<App *> apps_to_enable) { |
| 3072 | 3078 | } |
| 3073 | 3079 | |
| 3074 | 3080 | trigger_app->preparse_callback([apps_to_enable](std::size_t) { |
| 3075 | - for(auto &app : apps_to_enable) { | |
| 3081 | + for(const auto &app : apps_to_enable) { | |
| 3076 | 3082 | app->disabled(false); |
| 3077 | 3083 | } |
| 3078 | 3084 | }); |
| ... | ... | @@ -3093,7 +3099,7 @@ inline void TriggerOff(App *trigger_app, std::vector<App *> apps_to_enable) { |
| 3093 | 3099 | } |
| 3094 | 3100 | |
| 3095 | 3101 | trigger_app->preparse_callback([apps_to_enable](std::size_t) { |
| 3096 | - for(auto &app : apps_to_enable) { | |
| 3102 | + for(const auto &app : apps_to_enable) { | |
| 3097 | 3103 | app->disabled(); |
| 3098 | 3104 | } |
| 3099 | 3105 | }); |
| ... | ... | @@ -3116,31 +3122,31 @@ inline void deprecate_option(Option *opt, const std::string &replacement = "") { |
| 3116 | 3122 | |
| 3117 | 3123 | /// Helper function to mark an option as deprecated |
| 3118 | 3124 | inline void deprecate_option(App *app, const std::string &option_name, const std::string &replacement = "") { |
| 3119 | - auto opt = app->get_option(option_name); | |
| 3125 | + auto *opt = app->get_option(option_name); | |
| 3120 | 3126 | deprecate_option(opt, replacement); |
| 3121 | 3127 | } |
| 3122 | 3128 | |
| 3123 | 3129 | /// Helper function to mark an option as deprecated |
| 3124 | 3130 | inline void deprecate_option(App &app, const std::string &option_name, const std::string &replacement = "") { |
| 3125 | - auto opt = app.get_option(option_name); | |
| 3131 | + auto *opt = app.get_option(option_name); | |
| 3126 | 3132 | deprecate_option(opt, replacement); |
| 3127 | 3133 | } |
| 3128 | 3134 | |
| 3129 | 3135 | /// Helper function to mark an option as retired |
| 3130 | 3136 | inline void retire_option(App *app, Option *opt) { |
| 3131 | 3137 | App temp; |
| 3132 | - auto option_copy = temp.add_option(opt->get_name(false, true)) | |
| 3133 | - ->type_size(opt->get_type_size_min(), opt->get_type_size_max()) | |
| 3134 | - ->expected(opt->get_expected_min(), opt->get_expected_max()) | |
| 3135 | - ->allow_extra_args(opt->get_allow_extra_args()); | |
| 3138 | + auto *option_copy = temp.add_option(opt->get_name(false, true)) | |
| 3139 | + ->type_size(opt->get_type_size_min(), opt->get_type_size_max()) | |
| 3140 | + ->expected(opt->get_expected_min(), opt->get_expected_max()) | |
| 3141 | + ->allow_extra_args(opt->get_allow_extra_args()); | |
| 3136 | 3142 | |
| 3137 | 3143 | app->remove_option(opt); |
| 3138 | - auto opt2 = app->add_option(option_copy->get_name(false, true), "option has been retired and has no effect") | |
| 3139 | - ->type_name("RETIRED") | |
| 3140 | - ->default_str("RETIRED") | |
| 3141 | - ->type_size(option_copy->get_type_size_min(), option_copy->get_type_size_max()) | |
| 3142 | - ->expected(option_copy->get_expected_min(), option_copy->get_expected_max()) | |
| 3143 | - ->allow_extra_args(option_copy->get_allow_extra_args()); | |
| 3144 | + auto *opt2 = app->add_option(option_copy->get_name(false, true), "option has been retired and has no effect") | |
| 3145 | + ->type_name("RETIRED") | |
| 3146 | + ->default_str("RETIRED") | |
| 3147 | + ->type_size(option_copy->get_type_size_min(), option_copy->get_type_size_max()) | |
| 3148 | + ->expected(option_copy->get_expected_min(), option_copy->get_expected_max()) | |
| 3149 | + ->allow_extra_args(option_copy->get_allow_extra_args()); | |
| 3144 | 3150 | |
| 3145 | 3151 | Validator retired_warning{[opt2](std::string &) { |
| 3146 | 3152 | std::cout << "WARNING " << opt2->get_name() << " is retired and has no effect\n"; |
| ... | ... | @@ -3157,15 +3163,15 @@ inline void retire_option(App &app, Option *opt) { retire_option(&app, opt); } |
| 3157 | 3163 | /// Helper function to mark an option as retired |
| 3158 | 3164 | inline void retire_option(App *app, const std::string &option_name) { |
| 3159 | 3165 | |
| 3160 | - auto opt = app->get_option_no_throw(option_name); | |
| 3166 | + auto *opt = app->get_option_no_throw(option_name); | |
| 3161 | 3167 | if(opt != nullptr) { |
| 3162 | 3168 | retire_option(app, opt); |
| 3163 | 3169 | return; |
| 3164 | 3170 | } |
| 3165 | - auto opt2 = app->add_option(option_name, "option has been retired and has no effect") | |
| 3166 | - ->type_name("RETIRED") | |
| 3167 | - ->expected(0, 1) | |
| 3168 | - ->default_str("RETIRED"); | |
| 3171 | + auto *opt2 = app->add_option(option_name, "option has been retired and has no effect") | |
| 3172 | + ->type_name("RETIRED") | |
| 3173 | + ->expected(0, 1) | |
| 3174 | + ->default_str("RETIRED"); | |
| 3169 | 3175 | Validator retired_warning{[opt2](std::string &) { |
| 3170 | 3176 | std::cout << "WARNING " << opt2->get_name() << " is retired and has no effect\n"; |
| 3171 | 3177 | return std::string(); | ... | ... |
include/CLI/Config.hpp
| ... | ... | @@ -8,6 +8,7 @@ |
| 8 | 8 | |
| 9 | 9 | // [CLI11:public_includes:set] |
| 10 | 10 | #include <algorithm> |
| 11 | +#include <cctype> | |
| 11 | 12 | #include <fstream> |
| 12 | 13 | #include <iostream> |
| 13 | 14 | #include <string> |
| ... | ... | @@ -33,7 +34,7 @@ inline std::string convert_arg_for_ini(const std::string &arg, char stringQuote |
| 33 | 34 | } |
| 34 | 35 | // floating point conversion can convert some hex codes, but don't try that here |
| 35 | 36 | if(arg.compare(0, 2, "0x") != 0 && arg.compare(0, 2, "0X") != 0) { |
| 36 | - double val; | |
| 37 | + double val = 0.0; | |
| 37 | 38 | if(detail::lexical_cast(arg, val)) { |
| 38 | 39 | return arg; |
| 39 | 40 | } |
| ... | ... | @@ -62,9 +63,8 @@ inline std::string convert_arg_for_ini(const std::string &arg, char stringQuote |
| 62 | 63 | } |
| 63 | 64 | if(arg.find_first_of(stringQuote) == std::string::npos) { |
| 64 | 65 | return std::string(1, stringQuote) + arg + stringQuote; |
| 65 | - } else { | |
| 66 | - return characterQuote + arg + characterQuote; | |
| 67 | 66 | } |
| 67 | + return characterQuote + arg + characterQuote; | |
| 68 | 68 | } |
| 69 | 69 | |
| 70 | 70 | /// Comma separated join, adds quotes if needed |
| ... | ... | @@ -82,7 +82,7 @@ inline std::string ini_join(const std::vector<std::string> &args, |
| 82 | 82 | for(const auto &arg : args) { |
| 83 | 83 | if(start++ > 0) { |
| 84 | 84 | joined.push_back(sepChar); |
| 85 | - if(isspace(sepChar) == 0) { | |
| 85 | + if(!std::isspace<char>(sepChar, std::locale())) { | |
| 86 | 86 | joined.push_back(' '); |
| 87 | 87 | } |
| 88 | 88 | } |
| ... | ... | @@ -230,7 +230,7 @@ inline std::vector<ConfigItem> ConfigBase::from_config(std::istream &input) cons |
| 230 | 230 | std::string item = detail::trim_copy(line.substr(pos + 1)); |
| 231 | 231 | auto cloc = item.find(commentChar); |
| 232 | 232 | if(cloc != std::string::npos) { |
| 233 | - item.erase(cloc, std::string::npos); | |
| 233 | + item.erase(cloc, std::string::npos); // NOLINT(readability-suspicious-call-argument) | |
| 234 | 234 | detail::trim(item); |
| 235 | 235 | } |
| 236 | 236 | if(item.size() > 1 && item.front() == aStart) { |
| ... | ... | @@ -250,7 +250,7 @@ inline std::vector<ConfigItem> ConfigBase::from_config(std::istream &input) cons |
| 250 | 250 | name = detail::trim_copy(line); |
| 251 | 251 | auto cloc = name.find(commentChar); |
| 252 | 252 | if(cloc != std::string::npos) { |
| 253 | - name.erase(cloc, std::string::npos); | |
| 253 | + name.erase(cloc, std::string::npos); // NOLINT(readability-suspicious-call-argument) | |
| 254 | 254 | detail::trim(name); |
| 255 | 255 | } |
| 256 | 256 | |
| ... | ... | @@ -374,7 +374,7 @@ ConfigBase::to_config(const App *app, bool default_also, bool write_description, |
| 374 | 374 | out << '[' << prefix << subcom->get_name() << "]\n"; |
| 375 | 375 | } else { |
| 376 | 376 | std::string subname = app->get_name() + parentSeparatorChar + subcom->get_name(); |
| 377 | - auto p = app->get_parent(); | |
| 377 | + const auto *p = app->get_parent(); | |
| 378 | 378 | while(p->get_parent() != nullptr) { |
| 379 | 379 | subname = p->get_name() + parentSeparatorChar + subname; |
| 380 | 380 | p = p->get_parent(); | ... | ... |
include/CLI/ConfigFwd.hpp
| ... | ... | @@ -34,7 +34,7 @@ struct ConfigItem { |
| 34 | 34 | std::vector<std::string> inputs{}; |
| 35 | 35 | |
| 36 | 36 | /// The list of parents and name joined by "." |
| 37 | - std::string fullname() const { | |
| 37 | + CLI11_NODISCARD std::string fullname() const { | |
| 38 | 38 | std::vector<std::string> tmp = parents; |
| 39 | 39 | tmp.emplace_back(name); |
| 40 | 40 | return detail::join(tmp, "."); |
| ... | ... | @@ -54,7 +54,7 @@ class Config { |
| 54 | 54 | virtual std::vector<ConfigItem> from_config(std::istream &) const = 0; |
| 55 | 55 | |
| 56 | 56 | /// Get a flag value |
| 57 | - virtual std::string to_flag(const ConfigItem &item) const { | |
| 57 | + CLI11_NODISCARD virtual std::string to_flag(const ConfigItem &item) const { | |
| 58 | 58 | if(item.inputs.size() == 1) { |
| 59 | 59 | return item.inputs.at(0); |
| 60 | 60 | } |
| ... | ... | @@ -65,7 +65,7 @@ class Config { |
| 65 | 65 | } |
| 66 | 66 | |
| 67 | 67 | /// Parse a config file, throw an error (ParseError:ConfigParseError or FileError) on failure |
| 68 | - std::vector<ConfigItem> from_file(const std::string &name) { | |
| 68 | + CLI11_NODISCARD std::vector<ConfigItem> from_file(const std::string &name) const { | |
| 69 | 69 | std::ifstream input{name}; |
| 70 | 70 | if(!input.good()) |
| 71 | 71 | throw FileError::Missing(name); |
| ... | ... | @@ -148,7 +148,7 @@ class ConfigBase : public Config { |
| 148 | 148 | /// get a reference to the configuration section |
| 149 | 149 | std::string §ionRef() { return configSection; } |
| 150 | 150 | /// get the section |
| 151 | - const std::string §ion() const { return configSection; } | |
| 151 | + CLI11_NODISCARD const std::string §ion() const { return configSection; } | |
| 152 | 152 | /// specify a particular section of the configuration file to use |
| 153 | 153 | ConfigBase *section(const std::string §ionName) { |
| 154 | 154 | configSection = sectionName; |
| ... | ... | @@ -158,7 +158,7 @@ class ConfigBase : public Config { |
| 158 | 158 | /// get a reference to the configuration index |
| 159 | 159 | int16_t &indexRef() { return configIndex; } |
| 160 | 160 | /// get the section index |
| 161 | - int16_t index() const { return configIndex; } | |
| 161 | + CLI11_NODISCARD int16_t index() const { return configIndex; } | |
| 162 | 162 | /// specify a particular index in the section to use (-1) for all sections to use |
| 163 | 163 | ConfigBase *index(int16_t sectionIndex) { |
| 164 | 164 | configIndex = sectionIndex; | ... | ... |
include/CLI/Error.hpp
| ... | ... | @@ -72,9 +72,9 @@ class Error : public std::runtime_error { |
| 72 | 72 | std::string error_name{"Error"}; |
| 73 | 73 | |
| 74 | 74 | public: |
| 75 | - int get_exit_code() const { return actual_exit_code; } | |
| 75 | + CLI11_NODISCARD int get_exit_code() const { return actual_exit_code; } | |
| 76 | 76 | |
| 77 | - std::string get_name() const { return error_name; } | |
| 77 | + CLI11_NODISCARD std::string get_name() const { return error_name; } | |
| 78 | 78 | |
| 79 | 79 | Error(std::string name, std::string msg, int exit_code = static_cast<int>(ExitCodes::BaseClass)) |
| 80 | 80 | : runtime_error(msg), actual_exit_code(exit_code), error_name(std::move(name)) {} |
| ... | ... | @@ -137,10 +137,10 @@ class OptionAlreadyAdded : public ConstructionError { |
| 137 | 137 | explicit OptionAlreadyAdded(std::string name) |
| 138 | 138 | : OptionAlreadyAdded(name + " is already added", ExitCodes::OptionAlreadyAdded) {} |
| 139 | 139 | static OptionAlreadyAdded Requires(std::string name, std::string other) { |
| 140 | - return OptionAlreadyAdded(name + " requires " + other, ExitCodes::OptionAlreadyAdded); | |
| 140 | + return {name + " requires " + other, ExitCodes::OptionAlreadyAdded}; | |
| 141 | 141 | } |
| 142 | 142 | static OptionAlreadyAdded Excludes(std::string name, std::string other) { |
| 143 | - return OptionAlreadyAdded(name + " excludes " + other, ExitCodes::OptionAlreadyAdded); | |
| 143 | + return {name + " excludes " + other, ExitCodes::OptionAlreadyAdded}; | |
| 144 | 144 | } |
| 145 | 145 | }; |
| 146 | 146 | |
| ... | ... | @@ -223,32 +223,30 @@ class RequiredError : public ParseError { |
| 223 | 223 | if(min_subcom == 1) { |
| 224 | 224 | return RequiredError("A subcommand"); |
| 225 | 225 | } |
| 226 | - return RequiredError("Requires at least " + std::to_string(min_subcom) + " subcommands", | |
| 227 | - ExitCodes::RequiredError); | |
| 226 | + return {"Requires at least " + std::to_string(min_subcom) + " subcommands", ExitCodes::RequiredError}; | |
| 228 | 227 | } |
| 229 | 228 | static RequiredError |
| 230 | 229 | Option(std::size_t min_option, std::size_t max_option, std::size_t used, const std::string &option_list) { |
| 231 | 230 | if((min_option == 1) && (max_option == 1) && (used == 0)) |
| 232 | 231 | return RequiredError("Exactly 1 option from [" + option_list + "]"); |
| 233 | 232 | if((min_option == 1) && (max_option == 1) && (used > 1)) { |
| 234 | - return RequiredError("Exactly 1 option from [" + option_list + "] is required and " + std::to_string(used) + | |
| 235 | - " were given", | |
| 236 | - ExitCodes::RequiredError); | |
| 233 | + return {"Exactly 1 option from [" + option_list + "] is required and " + std::to_string(used) + | |
| 234 | + " were given", | |
| 235 | + ExitCodes::RequiredError}; | |
| 237 | 236 | } |
| 238 | 237 | if((min_option == 1) && (used == 0)) |
| 239 | 238 | return RequiredError("At least 1 option from [" + option_list + "]"); |
| 240 | 239 | if(used < min_option) { |
| 241 | - return RequiredError("Requires at least " + std::to_string(min_option) + " options used and only " + | |
| 242 | - std::to_string(used) + "were given from [" + option_list + "]", | |
| 243 | - ExitCodes::RequiredError); | |
| 240 | + return {"Requires at least " + std::to_string(min_option) + " options used and only " + | |
| 241 | + std::to_string(used) + "were given from [" + option_list + "]", | |
| 242 | + ExitCodes::RequiredError}; | |
| 244 | 243 | } |
| 245 | 244 | if(max_option == 1) |
| 246 | - return RequiredError("Requires at most 1 options be given from [" + option_list + "]", | |
| 247 | - ExitCodes::RequiredError); | |
| 245 | + return {"Requires at most 1 options be given from [" + option_list + "]", ExitCodes::RequiredError}; | |
| 248 | 246 | |
| 249 | - return RequiredError("Requires at most " + std::to_string(max_option) + " options be used and " + | |
| 250 | - std::to_string(used) + "were given from [" + option_list + "]", | |
| 251 | - ExitCodes::RequiredError); | |
| 247 | + return {"Requires at most " + std::to_string(max_option) + " options be used and " + std::to_string(used) + | |
| 248 | + "were given from [" + option_list + "]", | |
| 249 | + ExitCodes::RequiredError}; | |
| 252 | 250 | } |
| 253 | 251 | }; |
| 254 | 252 | ... | ... |
include/CLI/Formatter.hpp
| ... | ... | @@ -35,7 +35,7 @@ inline std::string Formatter::make_positionals(const App *app) const { |
| 35 | 35 | app->get_options([](const Option *opt) { return !opt->get_group().empty() && opt->get_positional(); }); |
| 36 | 36 | |
| 37 | 37 | if(opts.empty()) |
| 38 | - return std::string(); | |
| 38 | + return {}; | |
| 39 | 39 | |
| 40 | 40 | return make_group(get_label("Positionals"), true, opts); |
| 41 | 41 | } | ... | ... |
include/CLI/FormatterFwd.hpp
| ... | ... | @@ -79,15 +79,14 @@ class FormatterBase { |
| 79 | 79 | ///@{ |
| 80 | 80 | |
| 81 | 81 | /// Get the current value of a name (REQUIRED, etc.) |
| 82 | - std::string get_label(std::string key) const { | |
| 82 | + CLI11_NODISCARD std::string get_label(std::string key) const { | |
| 83 | 83 | if(labels_.find(key) == labels_.end()) |
| 84 | 84 | return key; |
| 85 | - else | |
| 86 | - return labels_.at(key); | |
| 85 | + return labels_.at(key); | |
| 87 | 86 | } |
| 88 | 87 | |
| 89 | 88 | /// Get the current column width |
| 90 | - std::size_t get_column_width() const { return column_width_; } | |
| 89 | + CLI11_NODISCARD std::size_t get_column_width() const { return column_width_; } | |
| 91 | 90 | |
| 92 | 91 | ///@} |
| 93 | 92 | }; |
| ... | ... | @@ -125,7 +124,8 @@ class Formatter : public FormatterBase { |
| 125 | 124 | |
| 126 | 125 | /// This prints out a group of options with title |
| 127 | 126 | /// |
| 128 | - virtual std::string make_group(std::string group, bool is_positional, std::vector<const Option *> opts) const; | |
| 127 | + CLI11_NODISCARD virtual std::string | |
| 128 | + make_group(std::string group, bool is_positional, std::vector<const Option *> opts) const; | |
| 129 | 129 | |
| 130 | 130 | /// This prints out just the positionals "group" |
| 131 | 131 | virtual std::string make_positionals(const App *app) const; | ... | ... |
include/CLI/Macros.hpp
| ... | ... | @@ -41,6 +41,14 @@ |
| 41 | 41 | #define CLI11_DEPRECATED(reason) __attribute__((deprecated(reason))) |
| 42 | 42 | #endif |
| 43 | 43 | |
| 44 | +// GCC < 10 doesn't ignore this in unevaluated contexts | |
| 45 | +#if !defined(CLI11_CPP17) || \ | |
| 46 | + (defined(__GNUC__) && !defined(__llvm__) && !defined(__INTEL_COMPILER) && __GNUC__ < 10 && __GNUC__ > 4) | |
| 47 | +#define CLI11_NODISCARD | |
| 48 | +#else | |
| 49 | +#define CLI11_NODISCARD [[nodiscard]] | |
| 50 | +#endif | |
| 51 | + | |
| 44 | 52 | /** detection of rtti */ |
| 45 | 53 | #ifndef CLI11_USE_STATIC_RTTI |
| 46 | 54 | #if(defined(_HAS_STATIC_RTTI) && _HAS_STATIC_RTTI) | ... | ... |
include/CLI/Option.hpp
| ... | ... | @@ -119,44 +119,44 @@ template <typename CRTP> class OptionBase { |
| 119 | 119 | // Getters |
| 120 | 120 | |
| 121 | 121 | /// Get the group of this option |
| 122 | - const std::string &get_group() const { return group_; } | |
| 122 | + CLI11_NODISCARD const std::string &get_group() const { return group_; } | |
| 123 | 123 | |
| 124 | 124 | /// True if this is a required option |
| 125 | - bool get_required() const { return required_; } | |
| 125 | + CLI11_NODISCARD bool get_required() const { return required_; } | |
| 126 | 126 | |
| 127 | 127 | /// The status of ignore case |
| 128 | - bool get_ignore_case() const { return ignore_case_; } | |
| 128 | + CLI11_NODISCARD bool get_ignore_case() const { return ignore_case_; } | |
| 129 | 129 | |
| 130 | 130 | /// The status of ignore_underscore |
| 131 | - bool get_ignore_underscore() const { return ignore_underscore_; } | |
| 131 | + CLI11_NODISCARD bool get_ignore_underscore() const { return ignore_underscore_; } | |
| 132 | 132 | |
| 133 | 133 | /// The status of configurable |
| 134 | - bool get_configurable() const { return configurable_; } | |
| 134 | + CLI11_NODISCARD bool get_configurable() const { return configurable_; } | |
| 135 | 135 | |
| 136 | 136 | /// The status of configurable |
| 137 | - bool get_disable_flag_override() const { return disable_flag_override_; } | |
| 137 | + CLI11_NODISCARD bool get_disable_flag_override() const { return disable_flag_override_; } | |
| 138 | 138 | |
| 139 | 139 | /// Get the current delimiter char |
| 140 | - char get_delimiter() const { return delimiter_; } | |
| 140 | + CLI11_NODISCARD char get_delimiter() const { return delimiter_; } | |
| 141 | 141 | |
| 142 | 142 | /// Return true if this will automatically capture the default value for help printing |
| 143 | - bool get_always_capture_default() const { return always_capture_default_; } | |
| 143 | + CLI11_NODISCARD bool get_always_capture_default() const { return always_capture_default_; } | |
| 144 | 144 | |
| 145 | 145 | /// The status of the multi option policy |
| 146 | - MultiOptionPolicy get_multi_option_policy() const { return multi_option_policy_; } | |
| 146 | + CLI11_NODISCARD MultiOptionPolicy get_multi_option_policy() const { return multi_option_policy_; } | |
| 147 | 147 | |
| 148 | 148 | // Shortcuts for multi option policy |
| 149 | 149 | |
| 150 | 150 | /// Set the multi option policy to take last |
| 151 | 151 | CRTP *take_last() { |
| 152 | - auto self = static_cast<CRTP *>(this); | |
| 152 | + auto *self = static_cast<CRTP *>(this); | |
| 153 | 153 | self->multi_option_policy(MultiOptionPolicy::TakeLast); |
| 154 | 154 | return self; |
| 155 | 155 | } |
| 156 | 156 | |
| 157 | 157 | /// Set the multi option policy to take last |
| 158 | 158 | CRTP *take_first() { |
| 159 | - auto self = static_cast<CRTP *>(this); | |
| 159 | + auto *self = static_cast<CRTP *>(this); | |
| 160 | 160 | self->multi_option_policy(MultiOptionPolicy::TakeFirst); |
| 161 | 161 | return self; |
| 162 | 162 | } |
| ... | ... | @@ -170,7 +170,7 @@ template <typename CRTP> class OptionBase { |
| 170 | 170 | |
| 171 | 171 | /// Set the multi option policy to join |
| 172 | 172 | CRTP *join() { |
| 173 | - auto self = static_cast<CRTP *>(this); | |
| 173 | + auto *self = static_cast<CRTP *>(this); | |
| 174 | 174 | self->multi_option_policy(MultiOptionPolicy::Join); |
| 175 | 175 | return self; |
| 176 | 176 | } |
| ... | ... | @@ -361,10 +361,10 @@ class Option : public OptionBase<Option> { |
| 361 | 361 | Option &operator=(const Option &) = delete; |
| 362 | 362 | |
| 363 | 363 | /// Count the total number of times an option was passed |
| 364 | - std::size_t count() const { return results_.size(); } | |
| 364 | + CLI11_NODISCARD std::size_t count() const { return results_.size(); } | |
| 365 | 365 | |
| 366 | 366 | /// True if the option was not passed |
| 367 | - bool empty() const { return results_.empty(); } | |
| 367 | + CLI11_NODISCARD bool empty() const { return results_.empty(); } | |
| 368 | 368 | |
| 369 | 369 | /// This bool operator returns true if any arguments were passed or the option callback is forced |
| 370 | 370 | explicit operator bool() const { return !empty() || force_callback_; } |
| ... | ... | @@ -427,14 +427,14 @@ class Option : public OptionBase<Option> { |
| 427 | 427 | return this; |
| 428 | 428 | } |
| 429 | 429 | /// Get the current value of allow extra args |
| 430 | - bool get_allow_extra_args() const { return allow_extra_args_; } | |
| 430 | + CLI11_NODISCARD bool get_allow_extra_args() const { return allow_extra_args_; } | |
| 431 | 431 | /// Set the value of trigger_on_parse which specifies that the option callback should be triggered on every parse |
| 432 | 432 | Option *trigger_on_parse(bool value = true) { |
| 433 | 433 | trigger_on_result_ = value; |
| 434 | 434 | return this; |
| 435 | 435 | } |
| 436 | 436 | /// The status of trigger on parse |
| 437 | - bool get_trigger_on_parse() const { return trigger_on_result_; } | |
| 437 | + CLI11_NODISCARD bool get_trigger_on_parse() const { return trigger_on_result_; } | |
| 438 | 438 | |
| 439 | 439 | /// Set the value of force_callback |
| 440 | 440 | Option *force_callback(bool value = true) { |
| ... | ... | @@ -442,7 +442,7 @@ class Option : public OptionBase<Option> { |
| 442 | 442 | return this; |
| 443 | 443 | } |
| 444 | 444 | /// The status of force_callback |
| 445 | - bool get_force_callback() const { return force_callback_; } | |
| 445 | + CLI11_NODISCARD bool get_force_callback() const { return force_callback_; } | |
| 446 | 446 | |
| 447 | 447 | /// Set the value of run_callback_for_default which controls whether the callback function should be called to set |
| 448 | 448 | /// the default This is controlled automatically but could be manipulated by the user. |
| ... | ... | @@ -451,7 +451,7 @@ class Option : public OptionBase<Option> { |
| 451 | 451 | return this; |
| 452 | 452 | } |
| 453 | 453 | /// Get the current value of run_callback_for_default |
| 454 | - bool get_run_callback_for_default() const { return run_callback_for_default_; } | |
| 454 | + CLI11_NODISCARD bool get_run_callback_for_default() const { return run_callback_for_default_; } | |
| 455 | 455 | |
| 456 | 456 | /// Adds a Validator with a built in type name |
| 457 | 457 | Option *check(Validator validator, const std::string &validator_name = "") { |
| ... | ... | @@ -547,7 +547,7 @@ class Option : public OptionBase<Option> { |
| 547 | 547 | /// Any number supported, any mix of string and Opt |
| 548 | 548 | template <typename A, typename B, typename... ARG> Option *needs(A opt, B opt1, ARG... args) { |
| 549 | 549 | needs(opt); |
| 550 | - return needs(opt1, args...); | |
| 550 | + return needs(opt1, args...); // NOLINT(readability-suspicious-call-argument) | |
| 551 | 551 | } |
| 552 | 552 | |
| 553 | 553 | /// Remove needs link from an option. Returns true if the option really was in the needs list. |
| ... | ... | @@ -621,7 +621,7 @@ class Option : public OptionBase<Option> { |
| 621 | 621 | if(opt.get() == this) { |
| 622 | 622 | continue; |
| 623 | 623 | } |
| 624 | - auto &omatch = opt->matching_name(*this); | |
| 624 | + const auto &omatch = opt->matching_name(*this); | |
| 625 | 625 | if(!omatch.empty()) { |
| 626 | 626 | ignore_case_ = false; |
| 627 | 627 | throw OptionAlreadyAdded("adding ignore case caused a name conflict with " + omatch); |
| ... | ... | @@ -646,7 +646,7 @@ class Option : public OptionBase<Option> { |
| 646 | 646 | if(opt.get() == this) { |
| 647 | 647 | continue; |
| 648 | 648 | } |
| 649 | - auto &omatch = opt->matching_name(*this); | |
| 649 | + const auto &omatch = opt->matching_name(*this); | |
| 650 | 650 | if(!omatch.empty()) { |
| 651 | 651 | ignore_underscore_ = false; |
| 652 | 652 | throw OptionAlreadyAdded("adding ignore underscore caused a name conflict with " + omatch); |
| ... | ... | @@ -682,41 +682,41 @@ class Option : public OptionBase<Option> { |
| 682 | 682 | ///@{ |
| 683 | 683 | |
| 684 | 684 | /// The number of arguments the option expects |
| 685 | - int get_type_size() const { return type_size_min_; } | |
| 685 | + CLI11_NODISCARD int get_type_size() const { return type_size_min_; } | |
| 686 | 686 | |
| 687 | 687 | /// The minimum number of arguments the option expects |
| 688 | - int get_type_size_min() const { return type_size_min_; } | |
| 688 | + CLI11_NODISCARD int get_type_size_min() const { return type_size_min_; } | |
| 689 | 689 | /// The maximum number of arguments the option expects |
| 690 | - int get_type_size_max() const { return type_size_max_; } | |
| 690 | + CLI11_NODISCARD int get_type_size_max() const { return type_size_max_; } | |
| 691 | 691 | |
| 692 | 692 | /// Return the inject_separator flag |
| 693 | - int get_inject_separator() const { return inject_separator_; } | |
| 693 | + CLI11_NODISCARD bool get_inject_separator() const { return inject_separator_; } | |
| 694 | 694 | |
| 695 | 695 | /// The environment variable associated to this value |
| 696 | - std::string get_envname() const { return envname_; } | |
| 696 | + CLI11_NODISCARD std::string get_envname() const { return envname_; } | |
| 697 | 697 | |
| 698 | 698 | /// The set of options needed |
| 699 | - std::set<Option *> get_needs() const { return needs_; } | |
| 699 | + CLI11_NODISCARD std::set<Option *> get_needs() const { return needs_; } | |
| 700 | 700 | |
| 701 | 701 | /// The set of options excluded |
| 702 | - std::set<Option *> get_excludes() const { return excludes_; } | |
| 702 | + CLI11_NODISCARD std::set<Option *> get_excludes() const { return excludes_; } | |
| 703 | 703 | |
| 704 | 704 | /// The default value (for help printing) |
| 705 | - std::string get_default_str() const { return default_str_; } | |
| 705 | + CLI11_NODISCARD std::string get_default_str() const { return default_str_; } | |
| 706 | 706 | |
| 707 | 707 | /// Get the callback function |
| 708 | - callback_t get_callback() const { return callback_; } | |
| 708 | + CLI11_NODISCARD callback_t get_callback() const { return callback_; } | |
| 709 | 709 | |
| 710 | 710 | /// Get the long names |
| 711 | - const std::vector<std::string> &get_lnames() const { return lnames_; } | |
| 711 | + CLI11_NODISCARD const std::vector<std::string> &get_lnames() const { return lnames_; } | |
| 712 | 712 | |
| 713 | 713 | /// Get the short names |
| 714 | - const std::vector<std::string> &get_snames() const { return snames_; } | |
| 714 | + CLI11_NODISCARD const std::vector<std::string> &get_snames() const { return snames_; } | |
| 715 | 715 | |
| 716 | 716 | /// Get the flag names with specified default values |
| 717 | - const std::vector<std::string> &get_fnames() const { return fnames_; } | |
| 717 | + CLI11_NODISCARD const std::vector<std::string> &get_fnames() const { return fnames_; } | |
| 718 | 718 | /// Get a single name for the option, first of lname, pname, sname, envname |
| 719 | - const std::string &get_single_name() const { | |
| 719 | + CLI11_NODISCARD const std::string &get_single_name() const { | |
| 720 | 720 | if(!lnames_.empty()) { |
| 721 | 721 | return lnames_[0]; |
| 722 | 722 | } |
| ... | ... | @@ -729,35 +729,35 @@ class Option : public OptionBase<Option> { |
| 729 | 729 | return envname_; |
| 730 | 730 | } |
| 731 | 731 | /// The number of times the option expects to be included |
| 732 | - int get_expected() const { return expected_min_; } | |
| 732 | + CLI11_NODISCARD int get_expected() const { return expected_min_; } | |
| 733 | 733 | |
| 734 | 734 | /// The number of times the option expects to be included |
| 735 | - int get_expected_min() const { return expected_min_; } | |
| 735 | + CLI11_NODISCARD int get_expected_min() const { return expected_min_; } | |
| 736 | 736 | /// The max number of times the option expects to be included |
| 737 | - int get_expected_max() const { return expected_max_; } | |
| 737 | + CLI11_NODISCARD int get_expected_max() const { return expected_max_; } | |
| 738 | 738 | |
| 739 | 739 | /// The total min number of expected string values to be used |
| 740 | - int get_items_expected_min() const { return type_size_min_ * expected_min_; } | |
| 740 | + CLI11_NODISCARD int get_items_expected_min() const { return type_size_min_ * expected_min_; } | |
| 741 | 741 | |
| 742 | 742 | /// Get the maximum number of items expected to be returned and used for the callback |
| 743 | - int get_items_expected_max() const { | |
| 743 | + CLI11_NODISCARD int get_items_expected_max() const { | |
| 744 | 744 | int t = type_size_max_; |
| 745 | 745 | return detail::checked_multiply(t, expected_max_) ? t : detail::expected_max_vector_size; |
| 746 | 746 | } |
| 747 | 747 | /// The total min number of expected string values to be used |
| 748 | - int get_items_expected() const { return get_items_expected_min(); } | |
| 748 | + CLI11_NODISCARD int get_items_expected() const { return get_items_expected_min(); } | |
| 749 | 749 | |
| 750 | 750 | /// True if the argument can be given directly |
| 751 | - bool get_positional() const { return pname_.length() > 0; } | |
| 751 | + CLI11_NODISCARD bool get_positional() const { return pname_.length() > 0; } | |
| 752 | 752 | |
| 753 | 753 | /// True if option has at least one non-positional name |
| 754 | - bool nonpositional() const { return (snames_.size() + lnames_.size()) > 0; } | |
| 754 | + CLI11_NODISCARD bool nonpositional() const { return (snames_.size() + lnames_.size()) > 0; } | |
| 755 | 755 | |
| 756 | 756 | /// True if option has description |
| 757 | - bool has_description() const { return description_.length() > 0; } | |
| 757 | + CLI11_NODISCARD bool has_description() const { return description_.length() > 0; } | |
| 758 | 758 | |
| 759 | 759 | /// Get the description |
| 760 | - const std::string &get_description() const { return description_; } | |
| 760 | + CLI11_NODISCARD const std::string &get_description() const { return description_; } | |
| 761 | 761 | |
| 762 | 762 | /// Set the description |
| 763 | 763 | Option *description(std::string option_description) { |
| ... | ... | @@ -770,7 +770,7 @@ class Option : public OptionBase<Option> { |
| 770 | 770 | return this; |
| 771 | 771 | } |
| 772 | 772 | |
| 773 | - const std::string &get_option_text() const { return option_text_; } | |
| 773 | + CLI11_NODISCARD const std::string &get_option_text() const { return option_text_; } | |
| 774 | 774 | |
| 775 | 775 | ///@} |
| 776 | 776 | /// @name Help tools |
| ... | ... | @@ -780,8 +780,8 @@ class Option : public OptionBase<Option> { |
| 780 | 780 | /// Will include / prefer the positional name if positional is true. |
| 781 | 781 | /// If all_options is false, pick just the most descriptive name to show. |
| 782 | 782 | /// Use `get_name(true)` to get the positional name (replaces `get_pname`) |
| 783 | - std::string get_name(bool positional = false, ///< Show the positional name | |
| 784 | - bool all_options = false ///< Show every option | |
| 783 | + CLI11_NODISCARD std::string get_name(bool positional = false, ///< Show the positional name | |
| 784 | + bool all_options = false ///< Show every option | |
| 785 | 785 | ) const { |
| 786 | 786 | if(get_group().empty()) |
| 787 | 787 | return {}; // Hidden |
| ... | ... | @@ -867,7 +867,7 @@ class Option : public OptionBase<Option> { |
| 867 | 867 | } |
| 868 | 868 | |
| 869 | 869 | /// If options share any of the same names, find it |
| 870 | - const std::string &matching_name(const Option &other) const { | |
| 870 | + CLI11_NODISCARD const std::string &matching_name(const Option &other) const { | |
| 871 | 871 | static const std::string estring; |
| 872 | 872 | for(const std::string &sname : snames_) |
| 873 | 873 | if(other.check_sname(sname)) |
| ... | ... | @@ -891,7 +891,7 @@ class Option : public OptionBase<Option> { |
| 891 | 891 | bool operator==(const Option &other) const { return !matching_name(other).empty(); } |
| 892 | 892 | |
| 893 | 893 | /// Check a name. Requires "-" or "--" for short / long, supports positional name |
| 894 | - bool check_name(const std::string &name) const { | |
| 894 | + CLI11_NODISCARD bool check_name(const std::string &name) const { | |
| 895 | 895 | |
| 896 | 896 | if(name.length() > 2 && name[0] == '-' && name[1] == '-') |
| 897 | 897 | return check_lname(name.substr(2)); |
| ... | ... | @@ -921,17 +921,17 @@ class Option : public OptionBase<Option> { |
| 921 | 921 | } |
| 922 | 922 | |
| 923 | 923 | /// Requires "-" to be removed from string |
| 924 | - bool check_sname(std::string name) const { | |
| 924 | + CLI11_NODISCARD bool check_sname(std::string name) const { | |
| 925 | 925 | return (detail::find_member(std::move(name), snames_, ignore_case_) >= 0); |
| 926 | 926 | } |
| 927 | 927 | |
| 928 | 928 | /// Requires "--" to be removed from string |
| 929 | - bool check_lname(std::string name) const { | |
| 929 | + CLI11_NODISCARD bool check_lname(std::string name) const { | |
| 930 | 930 | return (detail::find_member(std::move(name), lnames_, ignore_case_, ignore_underscore_) >= 0); |
| 931 | 931 | } |
| 932 | 932 | |
| 933 | 933 | /// Requires "--" to be removed from string |
| 934 | - bool check_fname(std::string name) const { | |
| 934 | + CLI11_NODISCARD bool check_fname(std::string name) const { | |
| 935 | 935 | if(fnames_.empty()) { |
| 936 | 936 | return false; |
| 937 | 937 | } |
| ... | ... | @@ -940,7 +940,7 @@ class Option : public OptionBase<Option> { |
| 940 | 940 | |
| 941 | 941 | /// Get the value that goes for a flag, nominally gets the default value but allows for overrides if not |
| 942 | 942 | /// disabled |
| 943 | - std::string get_flag_value(const std::string &name, std::string input_value) const { | |
| 943 | + CLI11_NODISCARD std::string get_flag_value(const std::string &name, std::string input_value) const { | |
| 944 | 944 | static const std::string trueString{"true"}; |
| 945 | 945 | static const std::string falseString{"false"}; |
| 946 | 946 | static const std::string emptyString{"{}"}; |
| ... | ... | @@ -964,9 +964,8 @@ class Option : public OptionBase<Option> { |
| 964 | 964 | if((input_value.empty()) || (input_value == emptyString)) { |
| 965 | 965 | if(flag_like_) { |
| 966 | 966 | return (ind < 0) ? trueString : default_flag_values_[static_cast<std::size_t>(ind)].second; |
| 967 | - } else { | |
| 968 | - return (ind < 0) ? default_str_ : default_flag_values_[static_cast<std::size_t>(ind)].second; | |
| 969 | 967 | } |
| 968 | + return (ind < 0) ? default_str_ : default_flag_values_[static_cast<std::size_t>(ind)].second; | |
| 970 | 969 | } |
| 971 | 970 | if(ind < 0) { |
| 972 | 971 | return input_value; |
| ... | ... | @@ -1007,10 +1006,10 @@ class Option : public OptionBase<Option> { |
| 1007 | 1006 | } |
| 1008 | 1007 | |
| 1009 | 1008 | /// Get the current complete results set |
| 1010 | - const results_t &results() const { return results_; } | |
| 1009 | + CLI11_NODISCARD const results_t &results() const { return results_; } | |
| 1011 | 1010 | |
| 1012 | 1011 | /// Get a copy of the results |
| 1013 | - results_t reduced_results() const { | |
| 1012 | + CLI11_NODISCARD results_t reduced_results() const { | |
| 1014 | 1013 | results_t res = proc_results_.empty() ? results_ : proc_results_; |
| 1015 | 1014 | if(current_option_state_ < option_state::reduced) { |
| 1016 | 1015 | if(current_option_state_ == option_state::parsing) { |
| ... | ... | @@ -1030,7 +1029,7 @@ class Option : public OptionBase<Option> { |
| 1030 | 1029 | |
| 1031 | 1030 | /// Get the results as a specified type |
| 1032 | 1031 | template <typename T> void results(T &output) const { |
| 1033 | - bool retval; | |
| 1032 | + bool retval = false; | |
| 1034 | 1033 | if(current_option_state_ >= option_state::reduced || (results_.size() == 1 && validators_.empty())) { |
| 1035 | 1034 | const results_t &res = (proc_results_.empty()) ? results_ : proc_results_; |
| 1036 | 1035 | retval = detail::lexical_conversion<T, T>(res, output); |
| ... | ... | @@ -1060,14 +1059,14 @@ class Option : public OptionBase<Option> { |
| 1060 | 1059 | } |
| 1061 | 1060 | |
| 1062 | 1061 | /// Return the results as the specified type |
| 1063 | - template <typename T> T as() const { | |
| 1062 | + template <typename T> CLI11_NODISCARD T as() const { | |
| 1064 | 1063 | T output; |
| 1065 | 1064 | results(output); |
| 1066 | 1065 | return output; |
| 1067 | 1066 | } |
| 1068 | 1067 | |
| 1069 | 1068 | /// See if the callback has been run already |
| 1070 | - bool get_callback_run() const { return (current_option_state_ == option_state::callback_run); } | |
| 1069 | + CLI11_NODISCARD bool get_callback_run() const { return (current_option_state_ == option_state::callback_run); } | |
| 1071 | 1070 | |
| 1072 | 1071 | ///@} |
| 1073 | 1072 | /// @name Custom options |
| ... | ... | @@ -1181,10 +1180,10 @@ class Option : public OptionBase<Option> { |
| 1181 | 1180 | } |
| 1182 | 1181 | |
| 1183 | 1182 | /// Get the full typename for this option |
| 1184 | - std::string get_type_name() const { | |
| 1183 | + CLI11_NODISCARD std::string get_type_name() const { | |
| 1185 | 1184 | std::string full_type_name = type_name_(); |
| 1186 | 1185 | if(!validators_.empty()) { |
| 1187 | - for(auto &Validator : validators_) { | |
| 1186 | + for(const auto &Validator : validators_) { | |
| 1188 | 1187 | std::string vtype = Validator.get_description(); |
| 1189 | 1188 | if(!vtype.empty()) { |
| 1190 | 1189 | full_type_name += ":" + vtype; |
| ... | ... | @@ -1235,14 +1234,14 @@ class Option : public OptionBase<Option> { |
| 1235 | 1234 | } |
| 1236 | 1235 | |
| 1237 | 1236 | /** reduce the results in accordance with the MultiOptionPolicy |
| 1238 | - @param[out] res results are assigned to res if there if they are different | |
| 1237 | + @param[out] out results are assigned to res if there if they are different | |
| 1239 | 1238 | */ |
| 1240 | - void _reduce_results(results_t &res, const results_t &original) const { | |
| 1239 | + void _reduce_results(results_t &out, const results_t &original) const { | |
| 1241 | 1240 | |
| 1242 | 1241 | // max num items expected or length of vector, always at least 1 |
| 1243 | 1242 | // Only valid for a trimming policy |
| 1244 | 1243 | |
| 1245 | - res.clear(); | |
| 1244 | + out.clear(); | |
| 1246 | 1245 | // Operation depends on the policy setting |
| 1247 | 1246 | switch(multi_option_policy_) { |
| 1248 | 1247 | case MultiOptionPolicy::TakeAll: |
| ... | ... | @@ -1252,23 +1251,23 @@ class Option : public OptionBase<Option> { |
| 1252 | 1251 | std::size_t trim_size = std::min<std::size_t>( |
| 1253 | 1252 | static_cast<std::size_t>(std::max<int>(get_items_expected_max(), 1)), original.size()); |
| 1254 | 1253 | if(original.size() != trim_size) { |
| 1255 | - res.assign(original.end() - static_cast<results_t::difference_type>(trim_size), original.end()); | |
| 1254 | + out.assign(original.end() - static_cast<results_t::difference_type>(trim_size), original.end()); | |
| 1256 | 1255 | } |
| 1257 | 1256 | } break; |
| 1258 | 1257 | case MultiOptionPolicy::TakeFirst: { |
| 1259 | 1258 | std::size_t trim_size = std::min<std::size_t>( |
| 1260 | 1259 | static_cast<std::size_t>(std::max<int>(get_items_expected_max(), 1)), original.size()); |
| 1261 | 1260 | if(original.size() != trim_size) { |
| 1262 | - res.assign(original.begin(), original.begin() + static_cast<results_t::difference_type>(trim_size)); | |
| 1261 | + out.assign(original.begin(), original.begin() + static_cast<results_t::difference_type>(trim_size)); | |
| 1263 | 1262 | } |
| 1264 | 1263 | } break; |
| 1265 | 1264 | case MultiOptionPolicy::Join: |
| 1266 | 1265 | if(results_.size() > 1) { |
| 1267 | - res.push_back(detail::join(original, std::string(1, (delimiter_ == '.push_back(detail::join(original, std::string(1, (delimiter_ == '\0') ? '\n' : delimiter_)));') ? '\n' : delimiter_))); | |
| 1266 | + out.push_back(detail::join(original, std::string(1, (delimiter_ == '.push_back(detail::join(original, std::string(1, (delimiter_ == '\0') ? '\n' : delimiter_)));') ? '\n' : delimiter_))); | |
| 1268 | 1267 | } |
| 1269 | 1268 | break; |
| 1270 | 1269 | case MultiOptionPolicy::Sum: |
| 1271 | - res.push_back(detail::sum_string_vector(original)); | |
| 1270 | + out.push_back(detail::sum_string_vector(original)); | |
| 1272 | 1271 | break; |
| 1273 | 1272 | case MultiOptionPolicy::Throw: |
| 1274 | 1273 | default: { |
| ... | ... | @@ -1290,14 +1289,14 @@ class Option : public OptionBase<Option> { |
| 1290 | 1289 | } |
| 1291 | 1290 | } |
| 1292 | 1291 | // this check is to allow an empty vector in certain circumstances but not if expected is not zero. |
| 1293 | - // {} is the indicator for a an empty container | |
| 1294 | - if(res.empty()) { | |
| 1292 | + // {} is the indicator for an empty container | |
| 1293 | + if(out.empty()) { | |
| 1295 | 1294 | if(original.size() == 1 && original[0] == "{}" && get_items_expected_min() > 0) { |
| 1296 | - res.push_back("{}"); | |
| 1297 | - res.push_back("%%"); | |
| 1295 | + out.push_back("{}"); | |
| 1296 | + out.push_back("%%"); | |
| 1298 | 1297 | } |
| 1299 | - } else if(res.size() == 1 && res[0] == "{}" && get_items_expected_min() > 0) { | |
| 1300 | - res.push_back("%%"); | |
| 1298 | + } else if(out.size() == 1 && out[0] == "{}" && get_items_expected_min() > 0) { | |
| 1299 | + out.push_back("%%"); | |
| 1301 | 1300 | } |
| 1302 | 1301 | } |
| 1303 | 1302 | ... | ... |
include/CLI/Split.hpp
| ... | ... | @@ -66,8 +66,8 @@ inline bool split_windows_style(const std::string &current, std::string &name, s |
| 66 | 66 | // Splits a string into multiple long and short names |
| 67 | 67 | inline std::vector<std::string> split_names(std::string current) { |
| 68 | 68 | std::vector<std::string> output; |
| 69 | - std::size_t val; | |
| 70 | - while((val = current.find(",")) != std::string::npos) { | |
| 69 | + std::size_t val = 0; | |
| 70 | + while((val = current.find(',')) != std::string::npos) { | |
| 71 | 71 | output.push_back(trim_copy(current.substr(0, val))); |
| 72 | 72 | current = current.substr(val + 1); |
| 73 | 73 | } |
| ... | ... | @@ -94,7 +94,7 @@ inline std::vector<std::pair<std::string, std::string>> get_default_flag_values( |
| 94 | 94 | if((def_start != std::string::npos) && (flag.back() == '}')) { |
| 95 | 95 | defval = flag.substr(def_start + 1); |
| 96 | 96 | defval.pop_back(); |
| 97 | - flag.erase(def_start, std::string::npos); | |
| 97 | + flag.erase(def_start, std::string::npos); // NOLINT(readability-suspicious-call-argument) | |
| 98 | 98 | } |
| 99 | 99 | flag.erase(0, flag.find_first_not_of("-!")); |
| 100 | 100 | output.emplace_back(flag, defval); |
| ... | ... | @@ -134,8 +134,7 @@ get_names(const std::vector<std::string> &input) { |
| 134 | 134 | } |
| 135 | 135 | } |
| 136 | 136 | |
| 137 | - return std::tuple<std::vector<std::string>, std::vector<std::string>, std::string>( | |
| 138 | - short_names, long_names, pos_name); | |
| 137 | + return std::make_tuple(short_names, long_names, pos_name); | |
| 139 | 138 | } |
| 140 | 139 | |
| 141 | 140 | } // namespace detail | ... | ... |
include/CLI/StringTools.hpp
| ... | ... | @@ -347,7 +347,7 @@ inline std::vector<std::string> split_up(std::string str, char delimiter = '\0') |
| 347 | 347 | |
| 348 | 348 | const std::string delims("\'\"`"); |
| 349 | 349 | auto find_ws = [delimiter](char ch) { |
| 350 | - return (delimiter == '\0') ? (std::isspace<char>(ch, std::locale()) != 0) : (ch == delimiter); | |
| 350 | + return (delimiter == '\0') ? std::isspace<char>(ch, std::locale()) : (ch == delimiter); | |
| 351 | 351 | }; |
| 352 | 352 | trim(str); |
| 353 | 353 | ... | ... |
include/CLI/Timer.hpp
| ... | ... | @@ -12,6 +12,8 @@ |
| 12 | 12 | #define _GLIBCXX_USE_NANOSLEEP |
| 13 | 13 | #endif |
| 14 | 14 | |
| 15 | +#include <cmath> | |
| 16 | + | |
| 15 | 17 | #include <array> |
| 16 | 18 | #include <chrono> |
| 17 | 19 | #include <functional> |
| ... | ... | @@ -63,7 +65,7 @@ class Timer { |
| 63 | 65 | /// Time a function by running it multiple times. Target time is the len to target. |
| 64 | 66 | std::string time_it(std::function<void()> f, double target_time = 1) { |
| 65 | 67 | time_point start = start_; |
| 66 | - double total_time; | |
| 68 | + double total_time = NAN; | |
| 67 | 69 | |
| 68 | 70 | start_ = clock::now(); |
| 69 | 71 | std::size_t n = 0; |
| ... | ... | @@ -79,7 +81,7 @@ class Timer { |
| 79 | 81 | } |
| 80 | 82 | |
| 81 | 83 | /// This formats the numerical value for the time string |
| 82 | - std::string make_time_str() const { | |
| 84 | + std::string make_time_str() const { // NOLINT(modernize-use-nodiscard) | |
| 83 | 85 | time_point stop = clock::now(); |
| 84 | 86 | std::chrono::duration<double> elapsed = stop - start_; |
| 85 | 87 | double time = elapsed.count() / static_cast<double>(cycles); |
| ... | ... | @@ -88,7 +90,7 @@ class Timer { |
| 88 | 90 | |
| 89 | 91 | // LCOV_EXCL_START |
| 90 | 92 | /// This prints out a time string from a time |
| 91 | - std::string make_time_str(double time) const { | |
| 93 | + std::string make_time_str(double time) const { // NOLINT(modernize-use-nodiscard) | |
| 92 | 94 | auto print_it = [](double x, std::string unit) { |
| 93 | 95 | const unsigned int buffer_length = 50; |
| 94 | 96 | std::array<char, buffer_length> buffer; |
| ... | ... | @@ -98,17 +100,16 @@ class Timer { |
| 98 | 100 | |
| 99 | 101 | if(time < .000001) |
| 100 | 102 | return print_it(time * 1000000000, "ns"); |
| 101 | - else if(time < .001) | |
| 103 | + if(time < .001) | |
| 102 | 104 | return print_it(time * 1000000, "us"); |
| 103 | - else if(time < 1) | |
| 105 | + if(time < 1) | |
| 104 | 106 | return print_it(time * 1000, "ms"); |
| 105 | - else | |
| 106 | - return print_it(time, "s"); | |
| 107 | + return print_it(time, "s"); | |
| 107 | 108 | } |
| 108 | 109 | // LCOV_EXCL_STOP |
| 109 | 110 | |
| 110 | 111 | /// This is the main function, it creates a string |
| 111 | - std::string to_string() const { return time_print_(title_, make_time_str()); } | |
| 112 | + std::string to_string() const { return time_print_(title_, make_time_str()); } // NOLINT(modernize-use-nodiscard) | |
| 112 | 113 | |
| 113 | 114 | /// Division sets the number of cycles to divide by (no graphical change) |
| 114 | 115 | Timer &operator/(std::size_t val) { | ... | ... |
include/CLI/TypeTools.hpp
| ... | ... | @@ -276,7 +276,7 @@ template <typename T, |
| 276 | 276 | enable_if_t<std::is_constructible<std::string, T>::value && !std::is_convertible<T, std::string>::value, |
| 277 | 277 | detail::enabler> = detail::dummy> |
| 278 | 278 | std::string to_string(const T &value) { |
| 279 | - return std::string(value); | |
| 279 | + return std::string(value); // NOLINT(google-readability-casting) | |
| 280 | 280 | } |
| 281 | 281 | |
| 282 | 282 | /// Convert an object to a string (streaming must be supported for that type) |
| ... | ... | @@ -296,7 +296,7 @@ template <typename T, |
| 296 | 296 | !is_readable_container<typename std::remove_const<T>::type>::value, |
| 297 | 297 | detail::enabler> = detail::dummy> |
| 298 | 298 | std::string to_string(T &&) { |
| 299 | - return std::string{}; | |
| 299 | + return {}; | |
| 300 | 300 | } |
| 301 | 301 | |
| 302 | 302 | /// convert a readable container to a string |
| ... | ... | @@ -308,14 +308,14 @@ std::string to_string(T &&variable) { |
| 308 | 308 | auto cval = variable.begin(); |
| 309 | 309 | auto end = variable.end(); |
| 310 | 310 | if(cval == end) { |
| 311 | - return std::string("{}"); | |
| 311 | + return {"{}"}; | |
| 312 | 312 | } |
| 313 | 313 | std::vector<std::string> defaults; |
| 314 | 314 | while(cval != end) { |
| 315 | 315 | defaults.emplace_back(CLI::detail::to_string(*cval)); |
| 316 | 316 | ++cval; |
| 317 | 317 | } |
| 318 | - return std::string("[" + detail::join(defaults) + "]"); | |
| 318 | + return {"[" + detail::join(defaults) + "]"}; | |
| 319 | 319 | } |
| 320 | 320 | |
| 321 | 321 | /// special template overload |
| ... | ... | @@ -763,8 +763,8 @@ inline typename std::enable_if<I == type_count_base<T>::value, std::string>::typ |
| 763 | 763 | /// Recursively generate the tuple type name |
| 764 | 764 | template <typename T, std::size_t I> |
| 765 | 765 | inline typename std::enable_if<(I < type_count_base<T>::value), std::string>::type tuple_name() { |
| 766 | - std::string str = std::string(type_name<typename std::decay<typename std::tuple_element<I, T>::type>::type>()) + | |
| 767 | - ',' + tuple_name<T, I + 1>(); | |
| 766 | + auto str = std::string{type_name<typename std::decay<typename std::tuple_element<I, T>::type>::type>()} + ',' + | |
| 767 | + tuple_name<T, I + 1>(); | |
| 768 | 768 | if(str.back() == ',') |
| 769 | 769 | str.pop_back(); |
| 770 | 770 | return str; |
| ... | ... | @@ -843,7 +843,7 @@ inline std::int64_t to_flag_value(std::string val) { |
| 843 | 843 | return -1; |
| 844 | 844 | } |
| 845 | 845 | val = detail::to_lower(val); |
| 846 | - std::int64_t ret; | |
| 846 | + std::int64_t ret = 0; | |
| 847 | 847 | if(val.size() == 1) { |
| 848 | 848 | if(val[0] >= '1' && val[0] <= '9') { |
| 849 | 849 | return (static_cast<std::int64_t>(val[0]) - '0'); |
| ... | ... | @@ -1019,17 +1019,18 @@ template < |
| 1019 | 1019 | typename T, |
| 1020 | 1020 | enable_if_t<classify_object<T>::value == object_category::number_constructible, detail::enabler> = detail::dummy> |
| 1021 | 1021 | bool lexical_cast(const std::string &input, T &output) { |
| 1022 | - int val; | |
| 1022 | + int val = 0; | |
| 1023 | 1023 | if(integral_conversion(input, val)) { |
| 1024 | 1024 | output = T(val); |
| 1025 | 1025 | return true; |
| 1026 | - } else { | |
| 1027 | - double dval; | |
| 1028 | - if(lexical_cast(input, dval)) { | |
| 1029 | - output = T{dval}; | |
| 1030 | - return true; | |
| 1031 | - } | |
| 1032 | 1026 | } |
| 1027 | + | |
| 1028 | + double dval = 0.0; | |
| 1029 | + if(lexical_cast(input, dval)) { | |
| 1030 | + output = T{dval}; | |
| 1031 | + return true; | |
| 1032 | + } | |
| 1033 | + | |
| 1033 | 1034 | return from_stream(input, output); |
| 1034 | 1035 | } |
| 1035 | 1036 | |
| ... | ... | @@ -1038,7 +1039,7 @@ template < |
| 1038 | 1039 | typename T, |
| 1039 | 1040 | enable_if_t<classify_object<T>::value == object_category::integer_constructible, detail::enabler> = detail::dummy> |
| 1040 | 1041 | bool lexical_cast(const std::string &input, T &output) { |
| 1041 | - int val; | |
| 1042 | + int val = 0; | |
| 1042 | 1043 | if(integral_conversion(input, val)) { |
| 1043 | 1044 | output = T(val); |
| 1044 | 1045 | return true; |
| ... | ... | @@ -1051,7 +1052,7 @@ template < |
| 1051 | 1052 | typename T, |
| 1052 | 1053 | enable_if_t<classify_object<T>::value == object_category::double_constructible, detail::enabler> = detail::dummy> |
| 1053 | 1054 | bool lexical_cast(const std::string &input, T &output) { |
| 1054 | - double val; | |
| 1055 | + double val = 0.0; | |
| 1055 | 1056 | if(lexical_cast(input, val)) { |
| 1056 | 1057 | output = T{val}; |
| 1057 | 1058 | return true; |
| ... | ... | @@ -1064,7 +1065,7 @@ template <typename T, |
| 1064 | 1065 | enable_if_t<classify_object<T>::value == object_category::other && std::is_assignable<T &, int>::value, |
| 1065 | 1066 | detail::enabler> = detail::dummy> |
| 1066 | 1067 | bool lexical_cast(const std::string &input, T &output) { |
| 1067 | - int val; | |
| 1068 | + int val = 0; | |
| 1068 | 1069 | if(integral_conversion(input, val)) { |
| 1069 | 1070 | #ifdef _MSC_VER |
| 1070 | 1071 | #pragma warning(push) |
| ... | ... | @@ -1152,7 +1153,7 @@ bool lexical_assign(const std::string &input, AssignTo &output) { |
| 1152 | 1153 | output = 0; |
| 1153 | 1154 | return true; |
| 1154 | 1155 | } |
| 1155 | - int val; | |
| 1156 | + int val = 0; | |
| 1156 | 1157 | if(lexical_cast(input, val)) { |
| 1157 | 1158 | output = val; |
| 1158 | 1159 | return true; |
| ... | ... | @@ -1266,9 +1267,8 @@ bool lexical_conversion(const std::vector<std::string> &strings, AssignTo &outpu |
| 1266 | 1267 | output = ConvertTo{x, y}; |
| 1267 | 1268 | } |
| 1268 | 1269 | return worked; |
| 1269 | - } else { | |
| 1270 | - return lexical_assign<AssignTo, ConvertTo>(strings[0], output); | |
| 1271 | 1270 | } |
| 1271 | + return lexical_assign<AssignTo, ConvertTo>(strings[0], output); | |
| 1272 | 1272 | } |
| 1273 | 1273 | |
| 1274 | 1274 | /// Conversion to a vector type using a particular single type as the conversion type |
| ... | ... | @@ -1544,6 +1544,7 @@ inline std::string sum_string_vector(const std::vector<std::string> &values) { |
| 1544 | 1544 | } else { |
| 1545 | 1545 | if(val <= static_cast<double>((std::numeric_limits<std::int64_t>::min)()) || |
| 1546 | 1546 | val >= static_cast<double>((std::numeric_limits<std::int64_t>::max)()) || |
| 1547 | + // NOLINTNEXTLINE(clang-diagnostic-float-equal,bugprone-narrowing-conversions) | |
| 1547 | 1548 | val == static_cast<std::int64_t>(val)) { |
| 1548 | 1549 | output = detail::value_string(static_cast<int64_t>(val)); |
| 1549 | 1550 | } else { | ... | ... |
include/CLI/Validators.hpp
| ... | ... | @@ -94,6 +94,9 @@ class Validator { |
| 94 | 94 | /// specify that a validator should not modify the input |
| 95 | 95 | bool non_modifying_{false}; |
| 96 | 96 | |
| 97 | + Validator(std::string validator_desc, std::function<std::string(std::string &)> func) | |
| 98 | + : desc_function_([validator_desc]() { return validator_desc; }), func_(std::move(func)) {} | |
| 99 | + | |
| 97 | 100 | public: |
| 98 | 101 | Validator() = default; |
| 99 | 102 | /// Construct a Validator with just the description string |
| ... | ... | @@ -135,13 +138,13 @@ class Validator { |
| 135 | 138 | return *this; |
| 136 | 139 | } |
| 137 | 140 | /// Specify the type string |
| 138 | - Validator description(std::string validator_desc) const { | |
| 141 | + CLI11_NODISCARD Validator description(std::string validator_desc) const { | |
| 139 | 142 | Validator newval(*this); |
| 140 | 143 | newval.desc_function_ = [validator_desc]() { return validator_desc; }; |
| 141 | 144 | return newval; |
| 142 | 145 | } |
| 143 | 146 | /// Generate type description information for the Validator |
| 144 | - std::string get_description() const { | |
| 147 | + CLI11_NODISCARD std::string get_description() const { | |
| 145 | 148 | if(active_) { |
| 146 | 149 | return desc_function_(); |
| 147 | 150 | } |
| ... | ... | @@ -153,20 +156,20 @@ class Validator { |
| 153 | 156 | return *this; |
| 154 | 157 | } |
| 155 | 158 | /// Specify the type string |
| 156 | - Validator name(std::string validator_name) const { | |
| 159 | + CLI11_NODISCARD Validator name(std::string validator_name) const { | |
| 157 | 160 | Validator newval(*this); |
| 158 | 161 | newval.name_ = std::move(validator_name); |
| 159 | 162 | return newval; |
| 160 | 163 | } |
| 161 | 164 | /// Get the name of the Validator |
| 162 | - const std::string &get_name() const { return name_; } | |
| 165 | + CLI11_NODISCARD const std::string &get_name() const { return name_; } | |
| 163 | 166 | /// Specify whether the Validator is active or not |
| 164 | 167 | Validator &active(bool active_val = true) { |
| 165 | 168 | active_ = active_val; |
| 166 | 169 | return *this; |
| 167 | 170 | } |
| 168 | 171 | /// Specify whether the Validator is active or not |
| 169 | - Validator active(bool active_val = true) const { | |
| 172 | + CLI11_NODISCARD Validator active(bool active_val = true) const { | |
| 170 | 173 | Validator newval(*this); |
| 171 | 174 | newval.active_ = active_val; |
| 172 | 175 | return newval; |
| ... | ... | @@ -183,18 +186,18 @@ class Validator { |
| 183 | 186 | return *this; |
| 184 | 187 | } |
| 185 | 188 | /// Specify the application index of a validator |
| 186 | - Validator application_index(int app_index) const { | |
| 189 | + CLI11_NODISCARD Validator application_index(int app_index) const { | |
| 187 | 190 | Validator newval(*this); |
| 188 | 191 | newval.application_index_ = app_index; |
| 189 | 192 | return newval; |
| 190 | 193 | } |
| 191 | 194 | /// Get the current value of the application index |
| 192 | - int get_application_index() const { return application_index_; } | |
| 195 | + CLI11_NODISCARD int get_application_index() const { return application_index_; } | |
| 193 | 196 | /// Get a boolean if the validator is active |
| 194 | - bool get_active() const { return active_; } | |
| 197 | + CLI11_NODISCARD bool get_active() const { return active_; } | |
| 195 | 198 | |
| 196 | 199 | /// Get a boolean if the validator is allowed to modify the input returns true if it can modify the input |
| 197 | - bool get_modifying() const { return !non_modifying_; } | |
| 200 | + CLI11_NODISCARD bool get_modifying() const { return !non_modifying_; } | |
| 198 | 201 | |
| 199 | 202 | /// Combining validators is a new validator. Type comes from left validator if function, otherwise only set if the |
| 200 | 203 | /// same. |
| ... | ... | @@ -212,11 +215,10 @@ class Validator { |
| 212 | 215 | std::string s2 = f2(input); |
| 213 | 216 | if(!s1.empty() && !s2.empty()) |
| 214 | 217 | return std::string("(") + s1 + ") AND (" + s2 + ")"; |
| 215 | - else | |
| 216 | - return s1 + s2; | |
| 218 | + return s1 + s2; | |
| 217 | 219 | }; |
| 218 | 220 | |
| 219 | - newval.active_ = (active_ & other.active_); | |
| 221 | + newval.active_ = active_ && other.active_; | |
| 220 | 222 | newval.application_index_ = application_index_; |
| 221 | 223 | return newval; |
| 222 | 224 | } |
| ... | ... | @@ -240,7 +242,7 @@ class Validator { |
| 240 | 242 | |
| 241 | 243 | return std::string("(") + s1 + ") OR (" + s2 + ")"; |
| 242 | 244 | }; |
| 243 | - newval.active_ = (active_ & other.active_); | |
| 245 | + newval.active_ = active_ && other.active_; | |
| 244 | 246 | newval.application_index_ = application_index_; |
| 245 | 247 | return newval; |
| 246 | 248 | } |
| ... | ... | @@ -410,7 +412,7 @@ class IPV4Validator : public Validator { |
| 410 | 412 | if(result.size() != 4) { |
| 411 | 413 | return std::string("Invalid IPV4 address must have four parts (") + ip_addr + ')'; |
| 412 | 414 | } |
| 413 | - int num; | |
| 415 | + int num = 0; | |
| 414 | 416 | for(const auto &var : result) { |
| 415 | 417 | bool retval = detail::lexical_cast(var, num); |
| 416 | 418 | if(!retval) { |
| ... | ... | @@ -447,15 +449,14 @@ const detail::IPV4Validator ValidIPV4; |
| 447 | 449 | /// Validate the input as a particular type |
| 448 | 450 | template <typename DesiredType> class TypeValidator : public Validator { |
| 449 | 451 | public: |
| 450 | - explicit TypeValidator(const std::string &validator_name) : Validator(validator_name) { | |
| 451 | - func_ = [](std::string &input_string) { | |
| 452 | - auto val = DesiredType(); | |
| 453 | - if(!detail::lexical_cast(input_string, val)) { | |
| 454 | - return std::string("Failed parsing ") + input_string + " as a " + detail::type_name<DesiredType>(); | |
| 455 | - } | |
| 456 | - return std::string(); | |
| 457 | - }; | |
| 458 | - } | |
| 452 | + explicit TypeValidator(const std::string &validator_name) | |
| 453 | + : Validator(validator_name, [](std::string &input_string) { | |
| 454 | + auto val = DesiredType(); | |
| 455 | + if(!detail::lexical_cast(input_string, val)) { | |
| 456 | + return std::string("Failed parsing ") + input_string + " as a " + detail::type_name<DesiredType>(); | |
| 457 | + } | |
| 458 | + return std::string(); | |
| 459 | + }) {} | |
| 459 | 460 | TypeValidator() : TypeValidator(detail::type_name<DesiredType>()) {} |
| 460 | 461 | }; |
| 461 | 462 | |
| ... | ... | @@ -664,9 +665,8 @@ template <typename T> |
| 664 | 665 | inline typename std::enable_if<std::is_signed<T>::value, T>::type overflowCheck(const T &a, const T &b) { |
| 665 | 666 | if((a > 0) == (b > 0)) { |
| 666 | 667 | return ((std::numeric_limits<T>::max)() / (std::abs)(a) < (std::abs)(b)); |
| 667 | - } else { | |
| 668 | - return ((std::numeric_limits<T>::min)() / (std::abs)(a) > -(std::abs)(b)); | |
| 669 | 668 | } |
| 669 | + return ((std::numeric_limits<T>::min)() / (std::abs)(a) > -(std::abs)(b)); | |
| 670 | 670 | } |
| 671 | 671 | /// Do a check for overflow on unsigned numbers |
| 672 | 672 | template <typename T> |
| ... | ... | @@ -1056,6 +1056,10 @@ class AsNumberWithUnit : public Validator { |
| 1056 | 1056 | } |
| 1057 | 1057 | }; |
| 1058 | 1058 | |
| 1059 | +inline AsNumberWithUnit::Options operator|(const AsNumberWithUnit::Options &a, const AsNumberWithUnit::Options &b) { | |
| 1060 | + return static_cast<AsNumberWithUnit::Options>(static_cast<int>(a) | static_cast<int>(b)); | |
| 1061 | +} | |
| 1062 | + | |
| 1059 | 1063 | /// Converts a human-readable size string (with unit literal) to uin64_t size. |
| 1060 | 1064 | /// Example: |
| 1061 | 1065 | /// "100" => 100 |
| ... | ... | @@ -1111,10 +1115,9 @@ class AsSizeValue : public AsNumberWithUnit { |
| 1111 | 1115 | if(kb_is_1000) { |
| 1112 | 1116 | static auto m = init_mapping(true); |
| 1113 | 1117 | return m; |
| 1114 | - } else { | |
| 1115 | - static auto m = init_mapping(false); | |
| 1116 | - return m; | |
| 1117 | 1118 | } |
| 1119 | + static auto m = init_mapping(false); | |
| 1120 | + return m; | |
| 1118 | 1121 | } |
| 1119 | 1122 | }; |
| 1120 | 1123 | ... | ... |
tests/AppTest.cpp
| ... | ... | @@ -5,6 +5,8 @@ |
| 5 | 5 | // SPDX-License-Identifier: BSD-3-Clause |
| 6 | 6 | |
| 7 | 7 | #include "app_helper.hpp" |
| 8 | +#include <cmath> | |
| 9 | + | |
| 8 | 10 | #include <complex> |
| 9 | 11 | #include <cstdint> |
| 10 | 12 | #include <cstdlib> |
| ... | ... | @@ -30,10 +32,10 @@ TEST_CASE_METHOD(TApp, "OneFlagShortValues", "[app]") { |
| 30 | 32 | } |
| 31 | 33 | |
| 32 | 34 | TEST_CASE_METHOD(TApp, "OneFlagShortValuesAs", "[app]") { |
| 33 | - auto flg = app.add_flag("-c{1},--count{2}"); | |
| 35 | + auto *flg = app.add_flag("-c{1},--count{2}"); | |
| 34 | 36 | args = {"-c"}; |
| 35 | 37 | run(); |
| 36 | - auto opt = app["-c"]; | |
| 38 | + const auto *opt = app["-c"]; | |
| 37 | 39 | CHECK(1 == opt->as<int>()); |
| 38 | 40 | args = {"--count"}; |
| 39 | 41 | run(); |
| ... | ... | @@ -68,8 +70,8 @@ TEST_CASE_METHOD(TApp, "OneFlagShortWindows", "[app]") { |
| 68 | 70 | TEST_CASE_METHOD(TApp, "WindowsLongShortMix1", "[app]") { |
| 69 | 71 | app.allow_windows_style_options(); |
| 70 | 72 | |
| 71 | - auto a = app.add_flag("-c"); | |
| 72 | - auto b = app.add_flag("--c"); | |
| 73 | + auto *a = app.add_flag("-c"); | |
| 74 | + auto *b = app.add_flag("--c"); | |
| 73 | 75 | args = {"/c"}; |
| 74 | 76 | run(); |
| 75 | 77 | CHECK(a->count() == 1u); |
| ... | ... | @@ -79,8 +81,8 @@ TEST_CASE_METHOD(TApp, "WindowsLongShortMix1", "[app]") { |
| 79 | 81 | TEST_CASE_METHOD(TApp, "WindowsLongShortMix2", "[app]") { |
| 80 | 82 | app.allow_windows_style_options(); |
| 81 | 83 | |
| 82 | - auto a = app.add_flag("--c"); | |
| 83 | - auto b = app.add_flag("-c"); | |
| 84 | + auto *a = app.add_flag("--c"); | |
| 85 | + auto *b = app.add_flag("-c"); | |
| 84 | 86 | args = {"/c"}; |
| 85 | 87 | run(); |
| 86 | 88 | CHECK(a->count() == 1u); |
| ... | ... | @@ -160,7 +162,7 @@ TEST_CASE_METHOD(TApp, "RequireOptionsError", "[app]") { |
| 160 | 162 | |
| 161 | 163 | TEST_CASE_METHOD(TApp, "BoolFlagOverride", "[app]") { |
| 162 | 164 | bool val{false}; |
| 163 | - auto flg = app.add_flag("--this,--that", val); | |
| 165 | + auto *flg = app.add_flag("--this,--that", val); | |
| 164 | 166 | |
| 165 | 167 | app.parse("--this"); |
| 166 | 168 | CHECK(val); |
| ... | ... | @@ -200,7 +202,7 @@ TEST_CASE_METHOD(TApp, "OneFlagRefValue", "[app]") { |
| 200 | 202 | |
| 201 | 203 | TEST_CASE_METHOD(TApp, "OneFlagRefValueFalse", "[app]") { |
| 202 | 204 | int ref{0}; |
| 203 | - auto flg = app.add_flag("-c,--count", ref); | |
| 205 | + auto *flg = app.add_flag("-c,--count", ref); | |
| 204 | 206 | args = {"--count=false"}; |
| 205 | 207 | run(); |
| 206 | 208 | CHECK(app.count("-c") == 1u); |
| ... | ... | @@ -220,7 +222,7 @@ TEST_CASE_METHOD(TApp, "OneFlagRefValueFalse", "[app]") { |
| 220 | 222 | |
| 221 | 223 | TEST_CASE_METHOD(TApp, "FlagNegation", "[app]") { |
| 222 | 224 | int ref{0}; |
| 223 | - auto flg = app.add_flag("-c,--count,--ncount{false}", ref); | |
| 225 | + auto *flg = app.add_flag("-c,--count,--ncount{false}", ref); | |
| 224 | 226 | args = {"--count", "-c", "--ncount"}; |
| 225 | 227 | CHECK(!flg->check_fname("count")); |
| 226 | 228 | CHECK(flg->check_fname("ncount")); |
| ... | ... | @@ -437,7 +439,7 @@ TEST_CASE_METHOD(TApp, "OneStringFlagLike", "[app]") { |
| 437 | 439 | |
| 438 | 440 | TEST_CASE_METHOD(TApp, "OneIntFlagLike", "[app]") { |
| 439 | 441 | int val{0}; |
| 440 | - auto opt = app.add_option("-i", val)->expected(0, 1); | |
| 442 | + auto *opt = app.add_option("-i", val)->expected(0, 1); | |
| 441 | 443 | args = {"-i"}; |
| 442 | 444 | run(); |
| 443 | 445 | CHECK(app.count("-i") == 1u); |
| ... | ... | @@ -534,7 +536,7 @@ TEST_CASE_METHOD(TApp, "NumberFlags", "[app]") { |
| 534 | 536 | TEST_CASE_METHOD(TApp, "DisableFlagOverrideTest", "[app]") { |
| 535 | 537 | |
| 536 | 538 | int val{0}; |
| 537 | - auto opt = app.add_flag("--1{1},--2{2},--3{3},--4{4},--5{5},--6{6}, --7{7}, --8{8}, --9{9}", val); | |
| 539 | + auto *opt = app.add_flag("--1{1},--2{2},--3{3},--4{4},--5{5},--6{6}, --7{7}, --8{8}, --9{9}", val); | |
| 538 | 540 | CHECK(!opt->get_disable_flag_override()); |
| 539 | 541 | opt->disable_flag_override(); |
| 540 | 542 | args = {"--7=5"}; |
| ... | ... | @@ -609,7 +611,7 @@ TEST_CASE_METHOD(TApp, "StrangeOptionNames", "[app]") { |
| 609 | 611 | |
| 610 | 612 | TEST_CASE_METHOD(TApp, "FlagLikeOption", "[app]") { |
| 611 | 613 | bool val{false}; |
| 612 | - auto opt = app.add_option("--flag", val)->type_size(0)->default_str("true"); | |
| 614 | + auto *opt = app.add_option("--flag", val)->type_size(0)->default_str("true"); | |
| 613 | 615 | args = {"--flag"}; |
| 614 | 616 | run(); |
| 615 | 617 | CHECK(app.count("--flag") == 1u); |
| ... | ... | @@ -625,7 +627,7 @@ TEST_CASE_METHOD(TApp, "FlagLikeOption", "[app]") { |
| 625 | 627 | |
| 626 | 628 | TEST_CASE_METHOD(TApp, "FlagLikeIntOption", "[app]") { |
| 627 | 629 | int val{-47}; |
| 628 | - auto opt = app.add_option("--flag", val)->expected(0, 1); | |
| 630 | + auto *opt = app.add_option("--flag", val)->expected(0, 1); | |
| 629 | 631 | // normally some default value should be set, but this test is for some paths in the validators checks to skip |
| 630 | 632 | // validation on empty string if nothing is expected |
| 631 | 633 | opt->check(CLI::PositiveNumber); |
| ... | ... | @@ -678,7 +680,7 @@ TEST_CASE_METHOD(TApp, "ShortOpts", "[app]") { |
| 678 | 680 | TEST_CASE_METHOD(TApp, "TwoParamTemplateOpts", "[app]") { |
| 679 | 681 | |
| 680 | 682 | double funnyint{0.0}; |
| 681 | - auto opt = app.add_option<double, unsigned int>("-y", funnyint); | |
| 683 | + auto *opt = app.add_option<double, unsigned int>("-y", funnyint); | |
| 682 | 684 | |
| 683 | 685 | args = {"-y", "32"}; |
| 684 | 686 | |
| ... | ... | @@ -776,7 +778,7 @@ TEST_CASE_METHOD(TApp, "JoinOpt", "[app]") { |
| 776 | 778 | |
| 777 | 779 | TEST_CASE_METHOD(TApp, "SumOpt", "[app]") { |
| 778 | 780 | |
| 779 | - int val; | |
| 781 | + int val = 0; | |
| 780 | 782 | app.add_option("--val", val)->multi_option_policy(CLI::MultiOptionPolicy::Sum); |
| 781 | 783 | |
| 782 | 784 | args = {"--val=1", "--val=4"}; |
| ... | ... | @@ -788,7 +790,7 @@ TEST_CASE_METHOD(TApp, "SumOpt", "[app]") { |
| 788 | 790 | |
| 789 | 791 | TEST_CASE_METHOD(TApp, "SumOptFloat", "[app]") { |
| 790 | 792 | |
| 791 | - double val; | |
| 793 | + double val = NAN; | |
| 792 | 794 | app.add_option("--val", val)->multi_option_policy(CLI::MultiOptionPolicy::Sum); |
| 793 | 795 | |
| 794 | 796 | args = {"--val=1.3", "--val=-0.7"}; |
| ... | ... | @@ -846,7 +848,7 @@ TEST_CASE_METHOD(TApp, "TakeLastOptMulti_alternative_path", "[app]") { |
| 846 | 848 | |
| 847 | 849 | TEST_CASE_METHOD(TApp, "TakeLastOptMultiCheck", "[app]") { |
| 848 | 850 | std::vector<int> vals; |
| 849 | - auto opt = app.add_option("--long", vals)->expected(-2)->take_last(); | |
| 851 | + auto *opt = app.add_option("--long", vals)->expected(-2)->take_last(); | |
| 850 | 852 | |
| 851 | 853 | opt->check(CLI::Validator(CLI::PositiveNumber).application_index(0)); |
| 852 | 854 | opt->check((!CLI::PositiveNumber).application_index(1)); |
| ... | ... | @@ -979,7 +981,7 @@ TEST_CASE_METHOD(TApp, "emptyVectorReturn", "[app]") { |
| 979 | 981 | |
| 980 | 982 | std::vector<std::string> strs; |
| 981 | 983 | std::vector<std::string> strs2; |
| 982 | - auto opt1 = app.add_option("--str", strs)->required()->expected(0, 2); | |
| 984 | + auto *opt1 = app.add_option("--str", strs)->required()->expected(0, 2); | |
| 983 | 985 | app.add_option("--str2", strs2); |
| 984 | 986 | args = {"--str"}; |
| 985 | 987 | |
| ... | ... | @@ -995,13 +997,13 @@ TEST_CASE_METHOD(TApp, "emptyVectorReturn", "[app]") { |
| 995 | 997 | |
| 996 | 998 | run(); |
| 997 | 999 | |
| 998 | - CHECK(std::vector<std::string>{} == strs); | |
| 1000 | + CHECK(strs.empty()); | |
| 999 | 1001 | CHECK(std::vector<std::string>{"{}"} == strs2); |
| 1000 | 1002 | opt1->default_str("{}"); |
| 1001 | 1003 | args = {"--str"}; |
| 1002 | 1004 | |
| 1003 | 1005 | CHECK_NOTHROW(run()); |
| 1004 | - CHECK(std::vector<std::string>{} == strs); | |
| 1006 | + CHECK(strs.empty()); | |
| 1005 | 1007 | } |
| 1006 | 1008 | |
| 1007 | 1009 | TEST_CASE_METHOD(TApp, "RequiredOptsDoubleShort", "[app]") { |
| ... | ... | @@ -1096,7 +1098,7 @@ TEST_CASE_METHOD(TApp, "RequiredPositionals", "[app]") { |
| 1096 | 1098 | sources.clear(); |
| 1097 | 1099 | run(); |
| 1098 | 1100 | |
| 1099 | - CHECK(0u == sources.size()); | |
| 1101 | + CHECK(sources.empty()); | |
| 1100 | 1102 | CHECK("a" == dest); |
| 1101 | 1103 | } |
| 1102 | 1104 | |
| ... | ... | @@ -1130,7 +1132,7 @@ TEST_CASE_METHOD(TApp, "RequiredPositionalVector", "[app]") { |
| 1130 | 1132 | // Tests positionals at end |
| 1131 | 1133 | TEST_CASE_METHOD(TApp, "RequiredPositionalValidation", "[app]") { |
| 1132 | 1134 | std::vector<std::string> sources; |
| 1133 | - int dest; // required | |
| 1135 | + int dest = 0; // required | |
| 1134 | 1136 | std::string d2; |
| 1135 | 1137 | app.add_option("src", sources); |
| 1136 | 1138 | app.add_option("dest", dest)->required()->check(CLI::PositiveNumber); |
| ... | ... | @@ -1214,10 +1216,10 @@ TEST_CASE_METHOD(TApp, "RequiredOptsUnlimited", "[app]") { |
| 1214 | 1216 | |
| 1215 | 1217 | app.allow_extras(false); |
| 1216 | 1218 | std::vector<std::string> remain; |
| 1217 | - auto popt = app.add_option("positional", remain); | |
| 1219 | + auto *popt = app.add_option("positional", remain); | |
| 1218 | 1220 | run(); |
| 1219 | 1221 | CHECK(std::vector<std::string>({"one", "two"}) == strs); |
| 1220 | - CHECK(std::vector<std::string>() == remain); | |
| 1222 | + CHECK(remain.empty()); | |
| 1221 | 1223 | |
| 1222 | 1224 | args = {"--str", "one", "--", "two"}; |
| 1223 | 1225 | |
| ... | ... | @@ -1265,7 +1267,7 @@ TEST_CASE_METHOD(TApp, "RequiredOptsUnlimitedShort", "[app]") { |
| 1265 | 1267 | app.add_option("positional", remain); |
| 1266 | 1268 | run(); |
| 1267 | 1269 | CHECK(std::vector<std::string>({"one", "two"}) == strs); |
| 1268 | - CHECK(std::vector<std::string>() == remain); | |
| 1270 | + CHECK(remain.empty()); | |
| 1269 | 1271 | |
| 1270 | 1272 | args = {"-s", "one", "--", "two"}; |
| 1271 | 1273 | |
| ... | ... | @@ -1492,7 +1494,7 @@ TEST_CASE_METHOD(TApp, "Positionals", "[app]") { |
| 1492 | 1494 | |
| 1493 | 1495 | TEST_CASE_METHOD(TApp, "ForcedPositional", "[app]") { |
| 1494 | 1496 | std::vector<std::string> posit; |
| 1495 | - auto one = app.add_flag("--one"); | |
| 1497 | + auto *one = app.add_flag("--one"); | |
| 1496 | 1498 | app.add_option("posit", posit); |
| 1497 | 1499 | |
| 1498 | 1500 | args = {"--one", "two", "three"}; |
| ... | ... | @@ -1597,7 +1599,7 @@ TEST_CASE_METHOD(TApp, "Reset", "[app]") { |
| 1597 | 1599 | |
| 1598 | 1600 | TEST_CASE_METHOD(TApp, "RemoveOption", "[app]") { |
| 1599 | 1601 | app.add_flag("--one"); |
| 1600 | - auto opt = app.add_flag("--two"); | |
| 1602 | + auto *opt = app.add_flag("--two"); | |
| 1601 | 1603 | |
| 1602 | 1604 | CHECK(app.remove_option(opt)); |
| 1603 | 1605 | CHECK(!app.remove_option(opt)); |
| ... | ... | @@ -1608,8 +1610,8 @@ TEST_CASE_METHOD(TApp, "RemoveOption", "[app]") { |
| 1608 | 1610 | } |
| 1609 | 1611 | |
| 1610 | 1612 | TEST_CASE_METHOD(TApp, "RemoveNeedsLinks", "[app]") { |
| 1611 | - auto one = app.add_flag("--one"); | |
| 1612 | - auto two = app.add_flag("--two"); | |
| 1613 | + auto *one = app.add_flag("--one"); | |
| 1614 | + auto *two = app.add_flag("--two"); | |
| 1613 | 1615 | |
| 1614 | 1616 | two->needs(one); |
| 1615 | 1617 | one->needs(two); |
| ... | ... | @@ -1622,8 +1624,8 @@ TEST_CASE_METHOD(TApp, "RemoveNeedsLinks", "[app]") { |
| 1622 | 1624 | } |
| 1623 | 1625 | |
| 1624 | 1626 | TEST_CASE_METHOD(TApp, "RemoveExcludesLinks", "[app]") { |
| 1625 | - auto one = app.add_flag("--one"); | |
| 1626 | - auto two = app.add_flag("--two"); | |
| 1627 | + auto *one = app.add_flag("--one"); | |
| 1628 | + auto *two = app.add_flag("--two"); | |
| 1627 | 1629 | |
| 1628 | 1630 | two->excludes(one); |
| 1629 | 1631 | one->excludes(two); |
| ... | ... | @@ -1640,7 +1642,7 @@ TEST_CASE_METHOD(TApp, "FileNotExists", "[app]") { |
| 1640 | 1642 | REQUIRE_NOTHROW(CLI::NonexistentPath(myfile)); |
| 1641 | 1643 | |
| 1642 | 1644 | std::string filename; |
| 1643 | - auto opt = app.add_option("--file", filename)->check(CLI::NonexistentPath, "path_check"); | |
| 1645 | + auto *opt = app.add_option("--file", filename)->check(CLI::NonexistentPath, "path_check"); | |
| 1644 | 1646 | args = {"--file", myfile}; |
| 1645 | 1647 | |
| 1646 | 1648 | run(); |
| ... | ... | @@ -1696,15 +1698,15 @@ TEST_CASE_METHOD(TApp, "NotFileExists", "[app]") { |
| 1696 | 1698 | TEST_CASE_METHOD(TApp, "DefaultedResult", "[app]") { |
| 1697 | 1699 | std::string sval = "NA"; |
| 1698 | 1700 | int ival{0}; |
| 1699 | - auto opts = app.add_option("--string", sval)->capture_default_str(); | |
| 1700 | - auto optv = app.add_option("--val", ival); | |
| 1701 | + auto *opts = app.add_option("--string", sval)->capture_default_str(); | |
| 1702 | + auto *optv = app.add_option("--val", ival); | |
| 1701 | 1703 | args = {}; |
| 1702 | 1704 | run(); |
| 1703 | 1705 | CHECK("NA" == sval); |
| 1704 | 1706 | std::string nString; |
| 1705 | 1707 | opts->results(nString); |
| 1706 | 1708 | CHECK("NA" == nString); |
| 1707 | - int newIval; | |
| 1709 | + int newIval = 0; | |
| 1708 | 1710 | // CHECK_THROWS_AS (optv->results(newIval), CLI::ConversionError); |
| 1709 | 1711 | optv->default_str("442"); |
| 1710 | 1712 | optv->results(newIval); |
| ... | ... | @@ -1791,7 +1793,7 @@ TEST_CASE_METHOD(TApp, "NeedsMultiFlags", "[app]") { |
| 1791 | 1793 | CLI::Option *opt1 = app.add_flag("--opt1"); |
| 1792 | 1794 | CLI::Option *opt2 = app.add_flag("--opt2"); |
| 1793 | 1795 | CLI::Option *opt3 = app.add_flag("--opt3"); |
| 1794 | - app.add_flag("--optall")->needs(opt1, opt2, opt3); | |
| 1796 | + app.add_flag("--optall")->needs(opt1, opt2, opt3); // NOLINT(readability-suspicious-call-argument) | |
| 1795 | 1797 | |
| 1796 | 1798 | run(); |
| 1797 | 1799 | |
| ... | ... | @@ -2121,20 +2123,20 @@ TEST_CASE_METHOD(TApp, "FallthroughParentFail", "[app]") { |
| 2121 | 2123 | } |
| 2122 | 2124 | |
| 2123 | 2125 | TEST_CASE_METHOD(TApp, "FallthroughParents", "[app]") { |
| 2124 | - auto sub = app.add_subcommand("test"); | |
| 2126 | + auto *sub = app.add_subcommand("test"); | |
| 2125 | 2127 | CHECK(&app == CLI::detail::AppFriend::get_fallthrough_parent(sub)); |
| 2126 | 2128 | |
| 2127 | - auto ssub = sub->add_subcommand("sub2"); | |
| 2129 | + auto *ssub = sub->add_subcommand("sub2"); | |
| 2128 | 2130 | CHECK(sub == CLI::detail::AppFriend::get_fallthrough_parent(ssub)); |
| 2129 | 2131 | |
| 2130 | - auto og1 = app.add_option_group("g1"); | |
| 2131 | - auto og2 = og1->add_option_group("g2"); | |
| 2132 | - auto og3 = og2->add_option_group("g3"); | |
| 2132 | + auto *og1 = app.add_option_group("g1"); | |
| 2133 | + auto *og2 = og1->add_option_group("g2"); | |
| 2134 | + auto *og3 = og2->add_option_group("g3"); | |
| 2133 | 2135 | CHECK(&app == CLI::detail::AppFriend::get_fallthrough_parent(og3)); |
| 2134 | 2136 | |
| 2135 | - auto ogb1 = sub->add_option_group("g1"); | |
| 2136 | - auto ogb2 = ogb1->add_option_group("g2"); | |
| 2137 | - auto ogb3 = ogb2->add_option_group("g3"); | |
| 2137 | + auto *ogb1 = sub->add_option_group("g1"); | |
| 2138 | + auto *ogb2 = ogb1->add_option_group("g2"); | |
| 2139 | + auto *ogb3 = ogb2->add_option_group("g3"); | |
| 2138 | 2140 | CHECK(sub == CLI::detail::AppFriend::get_fallthrough_parent(ogb3)); |
| 2139 | 2141 | |
| 2140 | 2142 | ogb2->name("groupb"); |
| ... | ... | @@ -2153,7 +2155,7 @@ TEST_CASE_METHOD(TApp, "OptionWithDefaults", "[app]") { |
| 2153 | 2155 | // Added to test ->transform |
| 2154 | 2156 | TEST_CASE_METHOD(TApp, "OrderedModifyingTransforms", "[app]") { |
| 2155 | 2157 | std::vector<std::string> val; |
| 2156 | - auto m = app.add_option("-m", val); | |
| 2158 | + auto *m = app.add_option("-m", val); | |
| 2157 | 2159 | m->transform([](std::string x) { return x + "1"; }); |
| 2158 | 2160 | m->transform([](std::string x) { return x + "2"; }); |
| 2159 | 2161 | |
| ... | ... | @@ -2166,7 +2168,7 @@ TEST_CASE_METHOD(TApp, "OrderedModifyingTransforms", "[app]") { |
| 2166 | 2168 | |
| 2167 | 2169 | TEST_CASE_METHOD(TApp, "ThrowingTransform", "[app]") { |
| 2168 | 2170 | std::string val; |
| 2169 | - auto m = app.add_option("-m,--mess", val); | |
| 2171 | + auto *m = app.add_option("-m,--mess", val); | |
| 2170 | 2172 | m->transform([](std::string) -> std::string { throw CLI::ValidationError("My Message"); }); |
| 2171 | 2173 | |
| 2172 | 2174 | REQUIRE_NOTHROW(run()); |
| ... | ... | @@ -2188,7 +2190,7 @@ TEST_CASE_METHOD(TApp, "EachItem", "[app]") { |
| 2188 | 2190 | std::vector<std::string> results; |
| 2189 | 2191 | std::vector<std::string> dummy; |
| 2190 | 2192 | |
| 2191 | - auto opt = app.add_option("--vec", dummy); | |
| 2193 | + auto *opt = app.add_option("--vec", dummy); | |
| 2192 | 2194 | |
| 2193 | 2195 | opt->each([&results](std::string item) { results.push_back(item); }); |
| 2194 | 2196 | |
| ... | ... | @@ -2259,7 +2261,7 @@ TEST_CASE_METHOD(TApp, "CustomUserSepParse", "[app]") { |
| 2259 | 2261 | |
| 2260 | 2262 | std::vector<int> vals{1, 2, 3}; |
| 2261 | 2263 | args = {"--idx", "1,2,3"}; |
| 2262 | - auto opt = app.add_option("--idx", vals)->delimiter(','); | |
| 2264 | + auto *opt = app.add_option("--idx", vals)->delimiter(','); | |
| 2263 | 2265 | run(); |
| 2264 | 2266 | CHECK(std::vector<int>({1, 2, 3}) == vals); |
| 2265 | 2267 | std::vector<int> vals2; |
| ... | ... | @@ -2279,7 +2281,7 @@ TEST_CASE_METHOD(TApp, "DefaultUserSepParse", "[app]") { |
| 2279 | 2281 | |
| 2280 | 2282 | std::vector<std::string> vals; |
| 2281 | 2283 | args = {"--idx", "1 2 3", "4 5 6"}; |
| 2282 | - auto opt = app.add_option("--idx", vals, ""); | |
| 2284 | + auto *opt = app.add_option("--idx", vals, ""); | |
| 2283 | 2285 | run(); |
| 2284 | 2286 | CHECK(std::vector<std::string>({"1 2 3", "4 5 6"}) == vals); |
| 2285 | 2287 | opt->delimiter(','); |
| ... | ... | @@ -2303,7 +2305,7 @@ TEST_CASE_METHOD(TApp, "CustomUserSepParse2", "[app]") { |
| 2303 | 2305 | |
| 2304 | 2306 | std::vector<int> vals{1, 2, 3}; |
| 2305 | 2307 | args = {"--idx", "1,2,"}; |
| 2306 | - auto opt = app.add_option("--idx", vals)->delimiter(','); | |
| 2308 | + auto *opt = app.add_option("--idx", vals)->delimiter(','); | |
| 2307 | 2309 | run(); |
| 2308 | 2310 | CHECK(std::vector<int>({1, 2}) == vals); |
| 2309 | 2311 | |
| ... | ... | @@ -2329,7 +2331,7 @@ TEST_CASE_METHOD(TApp, "CustomUserSepParseToggle", "[app]") { |
| 2329 | 2331 | |
| 2330 | 2332 | std::vector<std::string> vals; |
| 2331 | 2333 | args = {"--idx", "1,2,3"}; |
| 2332 | - auto opt = app.add_option("--idx", vals)->delimiter(','); | |
| 2334 | + auto *opt = app.add_option("--idx", vals)->delimiter(','); | |
| 2333 | 2335 | run(); |
| 2334 | 2336 | CHECK(std::vector<std::string>({"1", "2", "3"}) == vals); |
| 2335 | 2337 | opt->delimiter('\0'); |
| ... | ... | @@ -2348,7 +2350,7 @@ TEST_CASE_METHOD(TApp, "CustomUserSepParse3", "[app]") { |
| 2348 | 2350 | "1", |
| 2349 | 2351 | "," |
| 2350 | 2352 | "2"}; |
| 2351 | - auto opt = app.add_option("--idx", vals)->delimiter(','); | |
| 2353 | + auto *opt = app.add_option("--idx", vals)->delimiter(','); | |
| 2352 | 2354 | run(); |
| 2353 | 2355 | CHECK(std::vector<int>({1, 2}) == vals); |
| 2354 | 2356 | app.remove_option(opt); |
| ... | ... | @@ -2363,7 +2365,7 @@ TEST_CASE_METHOD(TApp, "CustomUserSepParse4", "[app]") { |
| 2363 | 2365 | |
| 2364 | 2366 | std::vector<int> vals; |
| 2365 | 2367 | args = {"--idx", "1, 2"}; |
| 2366 | - auto opt = app.add_option("--idx", vals)->delimiter(',')->capture_default_str(); | |
| 2368 | + auto *opt = app.add_option("--idx", vals)->delimiter(',')->capture_default_str(); | |
| 2367 | 2369 | run(); |
| 2368 | 2370 | CHECK(std::vector<int>({1, 2}) == vals); |
| 2369 | 2371 | |
| ... | ... | @@ -2379,7 +2381,7 @@ TEST_CASE_METHOD(TApp, "CustomUserSepParse5", "[app]") { |
| 2379 | 2381 | |
| 2380 | 2382 | std::vector<std::string> bar; |
| 2381 | 2383 | args = {"this", "is", "a", "test"}; |
| 2382 | - auto opt = app.add_option("bar", bar, "bar"); | |
| 2384 | + auto *opt = app.add_option("bar", bar, "bar"); | |
| 2383 | 2385 | run(); |
| 2384 | 2386 | CHECK(std::vector<std::string>({"this", "is", "a", "test"}) == bar); |
| 2385 | 2387 | |
| ... | ... | @@ -2421,7 +2423,7 @@ TEST_CASE_METHOD(TApp, "logFormSingleDash", "[app]") { |
| 2421 | 2423 | |
| 2422 | 2424 | TEST_CASE("C20_compile", "simple") { |
| 2423 | 2425 | CLI::App app{"test"}; |
| 2424 | - auto flag = app.add_flag("--flag", "desc"); | |
| 2426 | + auto *flag = app.add_flag("--flag", "desc"); | |
| 2425 | 2427 | |
| 2426 | 2428 | app.parse("--flag"); |
| 2427 | 2429 | CHECK_FALSE(flag->empty()); | ... | ... |
tests/ComplexTypeTest.cpp
| ... | ... | @@ -16,7 +16,7 @@ using cx = std::complex<double>; |
| 16 | 16 | CLI::Option * |
| 17 | 17 | add_option(CLI::App &app, std::string name, cx &variable, std::string description = "", bool defaulted = false) { |
| 18 | 18 | CLI::callback_t fun = [&variable](CLI::results_t res) { |
| 19 | - double x, y; | |
| 19 | + double x = 0, y = 0; | |
| 20 | 20 | bool worked = CLI::detail::lexical_cast(res[0], x) && CLI::detail::lexical_cast(res[1], y); |
| 21 | 21 | if(worked) |
| 22 | 22 | variable = cx(x, y); |
| ... | ... | @@ -89,7 +89,7 @@ template <> bool lexical_cast<std::complex<double>>(const std::string &input, st |
| 89 | 89 | |
| 90 | 90 | std::smatch m; |
| 91 | 91 | double x{0.0}, y{0.0}; |
| 92 | - bool worked; | |
| 92 | + bool worked = false; | |
| 93 | 93 | std::regex_search(input, m, creg); |
| 94 | 94 | if(m.size() == 9) { |
| 95 | 95 | worked = CLI::detail::lexical_cast(m[1], x) && CLI::detail::lexical_cast(m[6], y); |
| ... | ... | @@ -162,8 +162,8 @@ class complex_new { |
| 162 | 162 | public: |
| 163 | 163 | complex_new() = default; |
| 164 | 164 | complex_new(double v1, double v2) : val1_{v1}, val2_{v2} {}; |
| 165 | - double real() { return val1_; } | |
| 166 | - double imag() { return val2_; } | |
| 165 | + CLI11_NODISCARD double real() const { return val1_; } | |
| 166 | + CLI11_NODISCARD double imag() const { return val2_; } | |
| 167 | 167 | |
| 168 | 168 | private: |
| 169 | 169 | double val1_{0.0}; | ... | ... |
tests/ConfigFileTest.cpp
| ... | ... | @@ -47,15 +47,15 @@ TEST_CASE("StringBased: convert_arg_for_ini", "[config]") { |
| 47 | 47 | |
| 48 | 48 | TEST_CASE("StringBased: IniJoin", "[config]") { |
| 49 | 49 | std::vector<std::string> items = {"one", "two", "three four"}; |
| 50 | - std::string result = "\"one\" \"two\" \"three four\""; | |
| 50 | + std::string result = R"("one" "two" "three four")"; | |
| 51 | 51 | |
| 52 | 52 | CHECK(result == CLI::detail::ini_join(items, ' ', '\0', '\0')); |
| 53 | 53 | |
| 54 | - result = "[\"one\", \"two\", \"three four\"]"; | |
| 54 | + result = R"(["one", "two", "three four"])"; | |
| 55 | 55 | |
| 56 | 56 | CHECK(result == CLI::detail::ini_join(items)); |
| 57 | 57 | |
| 58 | - result = "{\"one\"; \"two\"; \"three four\"}"; | |
| 58 | + result = R"({"one"; "two"; "three four"})"; | |
| 59 | 59 | |
| 60 | 60 | CHECK(result == CLI::detail::ini_join(items, ';', '{', '}')); |
| 61 | 61 | } |
| ... | ... | @@ -260,7 +260,7 @@ TEST_CASE("StringBased: SpacesSections", "[config]") { |
| 260 | 260 | // check function to make sure that open sections match close sections |
| 261 | 261 | bool checkSections(const std::vector<CLI::ConfigItem> &output) { |
| 262 | 262 | std::set<std::string> open; |
| 263 | - for(auto &ci : output) { | |
| 263 | + for(const auto &ci : output) { | |
| 264 | 264 | if(ci.name == "++") { |
| 265 | 265 | auto nm = ci.fullname(); |
| 266 | 266 | nm.pop_back(); |
| ... | ... | @@ -525,7 +525,7 @@ TEST_CASE_METHOD(TApp, "IniGetNoRemaining", "[config]") { |
| 525 | 525 | int two{0}; |
| 526 | 526 | app.add_option("--two", two); |
| 527 | 527 | REQUIRE_NOTHROW(run()); |
| 528 | - CHECK(0u == app.remaining().size()); | |
| 528 | + CHECK(app.remaining().empty()); | |
| 529 | 529 | } |
| 530 | 530 | |
| 531 | 531 | TEST_CASE_METHOD(TApp, "IniRequiredNoDefault", "[config]") { |
| ... | ... | @@ -554,9 +554,9 @@ TEST_CASE_METHOD(TApp, "IniNotRequiredNoDefault", "[config]") { |
| 554 | 554 | class EvilConfig : public CLI::Config { |
| 555 | 555 | public: |
| 556 | 556 | EvilConfig() = default; |
| 557 | - virtual std::string to_config(const CLI::App *, bool, bool, std::string) const { throw CLI::FileError("evil"); } | |
| 557 | + std::string to_config(const CLI::App *, bool, bool, std::string) const override { throw CLI::FileError("evil"); } | |
| 558 | 558 | |
| 559 | - virtual std::vector<CLI::ConfigItem> from_config(std::istream &) const { throw CLI::FileError("evil"); } | |
| 559 | + std::vector<CLI::ConfigItem> from_config(std::istream &) const override { throw CLI::FileError("evil"); } | |
| 560 | 560 | }; |
| 561 | 561 | |
| 562 | 562 | TEST_CASE_METHOD(TApp, "IniRequiredbadConfigurator", "[config]") { |
| ... | ... | @@ -1121,9 +1121,9 @@ TEST_CASE_METHOD(TApp, "IniLayered", "[config]") { |
| 1121 | 1121 | |
| 1122 | 1122 | int one{0}, two{0}, three{0}; |
| 1123 | 1123 | app.add_option("--val", one); |
| 1124 | - auto subcom = app.add_subcommand("subcom"); | |
| 1124 | + auto *subcom = app.add_subcommand("subcom"); | |
| 1125 | 1125 | subcom->add_option("--val", two); |
| 1126 | - auto subsubcom = subcom->add_subcommand("subsubcom"); | |
| 1126 | + auto *subsubcom = subcom->add_subcommand("subsubcom"); | |
| 1127 | 1127 | subsubcom->add_option("--val", three); |
| 1128 | 1128 | |
| 1129 | 1129 | run(); |
| ... | ... | @@ -1153,9 +1153,9 @@ TEST_CASE_METHOD(TApp, "IniLayeredStream", "[config]") { |
| 1153 | 1153 | |
| 1154 | 1154 | int one{0}, two{0}, three{0}; |
| 1155 | 1155 | app.add_option("--val", one); |
| 1156 | - auto subcom = app.add_subcommand("subcom"); | |
| 1156 | + auto *subcom = app.add_subcommand("subcom"); | |
| 1157 | 1157 | subcom->add_option("--val", two); |
| 1158 | - auto subsubcom = subcom->add_subcommand("subsubcom"); | |
| 1158 | + auto *subsubcom = subcom->add_subcommand("subsubcom"); | |
| 1159 | 1159 | subsubcom->add_option("--val", three); |
| 1160 | 1160 | |
| 1161 | 1161 | std::ifstream in{tmpini}; |
| ... | ... | @@ -1187,9 +1187,9 @@ TEST_CASE_METHOD(TApp, "IniLayeredDotSection", "[config]") { |
| 1187 | 1187 | |
| 1188 | 1188 | int one{0}, two{0}, three{0}; |
| 1189 | 1189 | app.add_option("--val", one); |
| 1190 | - auto subcom = app.add_subcommand("subcom"); | |
| 1190 | + auto *subcom = app.add_subcommand("subcom"); | |
| 1191 | 1191 | subcom->add_option("--val", two); |
| 1192 | - auto subsubcom = subcom->add_subcommand("subsubcom"); | |
| 1192 | + auto *subsubcom = subcom->add_subcommand("subsubcom"); | |
| 1193 | 1193 | subsubcom->add_option("--val", three); |
| 1194 | 1194 | |
| 1195 | 1195 | run(); |
| ... | ... | @@ -1226,9 +1226,9 @@ TEST_CASE_METHOD(TApp, "IniLayeredCustomSectionSeparator", "[config]") { |
| 1226 | 1226 | app.get_config_formatter_base()->parentSeparator('|'); |
| 1227 | 1227 | int one{0}, two{0}, three{0}; |
| 1228 | 1228 | app.add_option("--val", one); |
| 1229 | - auto subcom = app.add_subcommand("subcom"); | |
| 1229 | + auto *subcom = app.add_subcommand("subcom"); | |
| 1230 | 1230 | subcom->add_option("--val", two); |
| 1231 | - auto subsubcom = subcom->add_subcommand("subsubcom"); | |
| 1231 | + auto *subsubcom = subcom->add_subcommand("subsubcom"); | |
| 1232 | 1232 | subsubcom->add_option("--val", three); |
| 1233 | 1233 | |
| 1234 | 1234 | run(); |
| ... | ... | @@ -1256,7 +1256,7 @@ TEST_CASE_METHOD(TApp, "IniLayeredOptionGroupAlias", "[config]") { |
| 1256 | 1256 | } |
| 1257 | 1257 | int one{0}, two{0}; |
| 1258 | 1258 | app.add_option("--val", one); |
| 1259 | - auto subcom = app.add_option_group("ogroup")->alias("ogroup"); | |
| 1259 | + auto *subcom = app.add_option_group("ogroup")->alias("ogroup"); | |
| 1260 | 1260 | subcom->add_option("--val2", two); |
| 1261 | 1261 | |
| 1262 | 1262 | run(); |
| ... | ... | @@ -1282,10 +1282,10 @@ TEST_CASE_METHOD(TApp, "IniSubcommandConfigurable", "[config]") { |
| 1282 | 1282 | |
| 1283 | 1283 | int one{0}, two{0}, three{0}; |
| 1284 | 1284 | app.add_option("--val", one); |
| 1285 | - auto subcom = app.add_subcommand("subcom"); | |
| 1285 | + auto *subcom = app.add_subcommand("subcom"); | |
| 1286 | 1286 | subcom->configurable(); |
| 1287 | 1287 | subcom->add_option("--val", two); |
| 1288 | - auto subsubcom = subcom->add_subcommand("subsubcom"); | |
| 1288 | + auto *subsubcom = subcom->add_subcommand("subsubcom"); | |
| 1289 | 1289 | subsubcom->add_option("--val", three); |
| 1290 | 1290 | |
| 1291 | 1291 | run(); |
| ... | ... | @@ -1316,15 +1316,15 @@ TEST_CASE_METHOD(TApp, "IniSubcommandConfigurablePreParse", "[config]") { |
| 1316 | 1316 | |
| 1317 | 1317 | int one{0}, two{0}, three{0}, four{0}; |
| 1318 | 1318 | app.add_option("--val", one); |
| 1319 | - auto subcom = app.add_subcommand("subcom"); | |
| 1320 | - auto subcom2 = app.add_subcommand("subcom2"); | |
| 1319 | + auto *subcom = app.add_subcommand("subcom"); | |
| 1320 | + auto *subcom2 = app.add_subcommand("subcom2"); | |
| 1321 | 1321 | subcom->configurable(); |
| 1322 | 1322 | std::vector<std::size_t> parse_c; |
| 1323 | 1323 | subcom->preparse_callback([&parse_c](std::size_t cnt) { parse_c.push_back(cnt); }); |
| 1324 | 1324 | subcom->add_option("--val", two); |
| 1325 | 1325 | subcom2->add_option("--val", four); |
| 1326 | 1326 | subcom2->preparse_callback([&parse_c](std::size_t cnt) { parse_c.push_back(cnt + 2623); }); |
| 1327 | - auto subsubcom = subcom->add_subcommand("subsubcom"); | |
| 1327 | + auto *subsubcom = subcom->add_subcommand("subsubcom"); | |
| 1328 | 1328 | subsubcom->add_option("--val", three); |
| 1329 | 1329 | |
| 1330 | 1330 | run(); |
| ... | ... | @@ -1399,7 +1399,7 @@ TEST_CASE_METHOD(TApp, "jsonLikeParsing", "[config]") { |
| 1399 | 1399 | std::ofstream out{tmpjson}; |
| 1400 | 1400 | out << "{" << std::endl; |
| 1401 | 1401 | out << "\"val\":1," << std::endl; |
| 1402 | - out << "\"val2\":\"test\"," << std::endl; | |
| 1402 | + out << R"("val2":"test",)" << std::endl; | |
| 1403 | 1403 | out << "\"flag\":true" << std::endl; |
| 1404 | 1404 | out << "}" << std::endl; |
| 1405 | 1405 | } |
| ... | ... | @@ -1482,15 +1482,15 @@ TEST_CASE_METHOD(TApp, "IniSubcommandConfigurableParseComplete", "[config]") { |
| 1482 | 1482 | |
| 1483 | 1483 | int one{0}, two{0}, three{0}, four{0}; |
| 1484 | 1484 | app.add_option("--val", one); |
| 1485 | - auto subcom = app.add_subcommand("subcom"); | |
| 1486 | - auto subcom2 = app.add_subcommand("subcom2"); | |
| 1485 | + auto *subcom = app.add_subcommand("subcom"); | |
| 1486 | + auto *subcom2 = app.add_subcommand("subcom2"); | |
| 1487 | 1487 | subcom->configurable(); |
| 1488 | 1488 | std::vector<std::size_t> parse_c; |
| 1489 | 1489 | subcom->parse_complete_callback([&parse_c]() { parse_c.push_back(58); }); |
| 1490 | 1490 | subcom->add_option("--val", two); |
| 1491 | 1491 | subcom2->add_option("--val", four); |
| 1492 | 1492 | subcom2->parse_complete_callback([&parse_c]() { parse_c.push_back(2623); }); |
| 1493 | - auto subsubcom = subcom->add_subcommand("subsubcom"); | |
| 1493 | + auto *subsubcom = subcom->add_subcommand("subsubcom"); | |
| 1494 | 1494 | // configurable should be inherited |
| 1495 | 1495 | subsubcom->parse_complete_callback([&parse_c]() { parse_c.push_back(68); }); |
| 1496 | 1496 | subsubcom->add_option("--val", three); |
| ... | ... | @@ -1529,8 +1529,8 @@ TEST_CASE_METHOD(TApp, "IniSubcommandMultipleSections", "[config]") { |
| 1529 | 1529 | |
| 1530 | 1530 | int one{0}, two{0}, three{0}, four{0}; |
| 1531 | 1531 | app.add_option("--val", one); |
| 1532 | - auto subcom = app.add_subcommand("subcom"); | |
| 1533 | - auto subcom2 = app.add_subcommand("subcom2"); | |
| 1532 | + auto *subcom = app.add_subcommand("subcom"); | |
| 1533 | + auto *subcom2 = app.add_subcommand("subcom2"); | |
| 1534 | 1534 | subcom->configurable(); |
| 1535 | 1535 | std::vector<std::size_t> parse_c; |
| 1536 | 1536 | subcom->parse_complete_callback([&parse_c]() { parse_c.push_back(58); }); |
| ... | ... | @@ -1538,7 +1538,7 @@ TEST_CASE_METHOD(TApp, "IniSubcommandMultipleSections", "[config]") { |
| 1538 | 1538 | subcom2->add_option("--val", four); |
| 1539 | 1539 | subcom2->parse_complete_callback([&parse_c]() { parse_c.push_back(2623); }); |
| 1540 | 1540 | subcom2->configurable(false); |
| 1541 | - auto subsubcom = subcom->add_subcommand("subsubcom"); | |
| 1541 | + auto *subsubcom = subcom->add_subcommand("subsubcom"); | |
| 1542 | 1542 | // configurable should be inherited |
| 1543 | 1543 | subsubcom->parse_complete_callback([&parse_c]() { parse_c.push_back(68); }); |
| 1544 | 1544 | subsubcom->add_option("--val", three); |
| ... | ... | @@ -1570,7 +1570,7 @@ TEST_CASE_METHOD(TApp, "DuplicateSubcommandCallbacks", "[config]") { |
| 1570 | 1570 | out << "[[foo]]" << std::endl; |
| 1571 | 1571 | } |
| 1572 | 1572 | |
| 1573 | - auto foo = app.add_subcommand("foo"); | |
| 1573 | + auto *foo = app.add_subcommand("foo"); | |
| 1574 | 1574 | int count{0}; |
| 1575 | 1575 | foo->callback([&count]() { ++count; }); |
| 1576 | 1576 | foo->immediate_callback(); |
| ... | ... | @@ -2161,7 +2161,7 @@ TEST_CASE_METHOD(TApp, "TomlOutputMultiLineDescription", "[config]") { |
| 2161 | 2161 | TEST_CASE_METHOD(TApp, "TomlOutputOptionGroupMultiLineDescription", "[config]") { |
| 2162 | 2162 | std::string flag = "flag"; |
| 2163 | 2163 | const std::string description = "Short flag description.\n"; |
| 2164 | - auto og = app.add_option_group("group"); | |
| 2164 | + auto *og = app.add_option_group("group"); | |
| 2165 | 2165 | og->description("Option group description.\n" |
| 2166 | 2166 | "That has multiple lines."); |
| 2167 | 2167 | og->add_flag("--" + flag, description); |
| ... | ... | @@ -2175,7 +2175,7 @@ TEST_CASE_METHOD(TApp, "TomlOutputOptionGroupMultiLineDescription", "[config]") |
| 2175 | 2175 | TEST_CASE_METHOD(TApp, "TomlOutputSubcommandMultiLineDescription", "[config]") { |
| 2176 | 2176 | std::string flag = "flag"; |
| 2177 | 2177 | const std::string description = "Short flag description.\n"; |
| 2178 | - auto subcom = app.add_subcommand("subcommand"); | |
| 2178 | + auto *subcom = app.add_subcommand("subcommand"); | |
| 2179 | 2179 | subcom->configurable(); |
| 2180 | 2180 | subcom->description("Subcommand description.\n" |
| 2181 | 2181 | "That has multiple lines."); |
| ... | ... | @@ -2195,7 +2195,7 @@ TEST_CASE_METHOD(TApp, "TomlOutputOptionGroup", "[config]") { |
| 2195 | 2195 | const std::string description2 = "Second description."; |
| 2196 | 2196 | app.add_flag("--" + flag1, description1)->group("group1"); |
| 2197 | 2197 | app.add_flag("--" + flag2, description2)->group("group2"); |
| 2198 | - auto og = app.add_option_group("group3", "g3 desc"); | |
| 2198 | + auto *og = app.add_option_group("group3", "g3 desc"); | |
| 2199 | 2199 | og->add_option("--dval", val)->capture_default_str()->group(""); |
| 2200 | 2200 | |
| 2201 | 2201 | run(); |
| ... | ... | @@ -2309,7 +2309,7 @@ TEST_CASE_METHOD(TApp, "TomlOutputDefault", "[config]") { |
| 2309 | 2309 | TEST_CASE_METHOD(TApp, "TomlOutputSubcom", "[config]") { |
| 2310 | 2310 | |
| 2311 | 2311 | app.add_flag("--simple"); |
| 2312 | - auto subcom = app.add_subcommand("other"); | |
| 2312 | + auto *subcom = app.add_subcommand("other"); | |
| 2313 | 2313 | subcom->add_flag("--newer"); |
| 2314 | 2314 | |
| 2315 | 2315 | args = {"--simple", "other", "--newer"}; |
| ... | ... | @@ -2323,7 +2323,7 @@ TEST_CASE_METHOD(TApp, "TomlOutputSubcom", "[config]") { |
| 2323 | 2323 | TEST_CASE_METHOD(TApp, "TomlOutputSubcomConfigurable", "[config]") { |
| 2324 | 2324 | |
| 2325 | 2325 | app.add_flag("--simple"); |
| 2326 | - auto subcom = app.add_subcommand("other")->configurable(); | |
| 2326 | + auto *subcom = app.add_subcommand("other")->configurable(); | |
| 2327 | 2327 | subcom->add_flag("--newer"); |
| 2328 | 2328 | |
| 2329 | 2329 | args = {"--simple", "other", "--newer"}; |
| ... | ... | @@ -2339,9 +2339,9 @@ TEST_CASE_METHOD(TApp, "TomlOutputSubcomConfigurable", "[config]") { |
| 2339 | 2339 | TEST_CASE_METHOD(TApp, "TomlOutputSubsubcom", "[config]") { |
| 2340 | 2340 | |
| 2341 | 2341 | app.add_flag("--simple"); |
| 2342 | - auto subcom = app.add_subcommand("other"); | |
| 2342 | + auto *subcom = app.add_subcommand("other"); | |
| 2343 | 2343 | subcom->add_flag("--newer"); |
| 2344 | - auto subsubcom = subcom->add_subcommand("sub2"); | |
| 2344 | + auto *subsubcom = subcom->add_subcommand("sub2"); | |
| 2345 | 2345 | subsubcom->add_flag("--newest"); |
| 2346 | 2346 | |
| 2347 | 2347 | args = {"--simple", "other", "--newer", "sub2", "--newest"}; |
| ... | ... | @@ -2356,10 +2356,10 @@ TEST_CASE_METHOD(TApp, "TomlOutputSubsubcom", "[config]") { |
| 2356 | 2356 | TEST_CASE_METHOD(TApp, "TomlOutputSubsubcomConfigurable", "[config]") { |
| 2357 | 2357 | |
| 2358 | 2358 | app.add_flag("--simple"); |
| 2359 | - auto subcom = app.add_subcommand("other")->configurable(); | |
| 2359 | + auto *subcom = app.add_subcommand("other")->configurable(); | |
| 2360 | 2360 | subcom->add_flag("--newer"); |
| 2361 | 2361 | |
| 2362 | - auto subsubcom = subcom->add_subcommand("sub2"); | |
| 2362 | + auto *subsubcom = subcom->add_subcommand("sub2"); | |
| 2363 | 2363 | subsubcom->add_flag("--newest"); |
| 2364 | 2364 | |
| 2365 | 2365 | args = {"--simple", "other", "--newer", "sub2", "--newest"}; |
| ... | ... | @@ -2377,10 +2377,10 @@ TEST_CASE_METHOD(TApp, "TomlOutputSubsubcomConfigurable", "[config]") { |
| 2377 | 2377 | TEST_CASE_METHOD(TApp, "TomlOutputSubcomNonConfigurable", "[config]") { |
| 2378 | 2378 | |
| 2379 | 2379 | app.add_flag("--simple"); |
| 2380 | - auto subcom = app.add_subcommand("other", "other_descriptor")->configurable(); | |
| 2380 | + auto *subcom = app.add_subcommand("other", "other_descriptor")->configurable(); | |
| 2381 | 2381 | subcom->add_flag("--newer"); |
| 2382 | 2382 | |
| 2383 | - auto subcom2 = app.add_subcommand("sub2", "descriptor2"); | |
| 2383 | + auto *subcom2 = app.add_subcommand("sub2", "descriptor2"); | |
| 2384 | 2384 | subcom2->add_flag("--newest")->configurable(false); |
| 2385 | 2385 | |
| 2386 | 2386 | args = {"--simple", "other", "--newer", "sub2", "--newest"}; |
| ... | ... | @@ -2398,14 +2398,14 @@ TEST_CASE_METHOD(TApp, "TomlOutputSubcomNonConfigurable", "[config]") { |
| 2398 | 2398 | TEST_CASE_METHOD(TApp, "TomlOutputSubsubcomConfigurableDeep", "[config]") { |
| 2399 | 2399 | |
| 2400 | 2400 | app.add_flag("--simple"); |
| 2401 | - auto subcom = app.add_subcommand("other")->configurable(); | |
| 2401 | + auto *subcom = app.add_subcommand("other")->configurable(); | |
| 2402 | 2402 | subcom->add_flag("--newer"); |
| 2403 | 2403 | |
| 2404 | - auto subsubcom = subcom->add_subcommand("sub2"); | |
| 2404 | + auto *subsubcom = subcom->add_subcommand("sub2"); | |
| 2405 | 2405 | subsubcom->add_flag("--newest"); |
| 2406 | - auto sssscom = subsubcom->add_subcommand("sub-level2"); | |
| 2406 | + auto *sssscom = subsubcom->add_subcommand("sub-level2"); | |
| 2407 | 2407 | subsubcom->add_flag("--still_newer"); |
| 2408 | - auto s5com = sssscom->add_subcommand("sub-level3"); | |
| 2408 | + auto *s5com = sssscom->add_subcommand("sub-level3"); | |
| 2409 | 2409 | s5com->add_flag("--absolute_newest"); |
| 2410 | 2410 | |
| 2411 | 2411 | args = {"--simple", "other", "sub2", "sub-level2", "sub-level3", "--absolute_newest"}; |
| ... | ... | @@ -2459,7 +2459,7 @@ TEST_CASE_METHOD(TApp, "StopReadingConfigOnClear", "[config]") { |
| 2459 | 2459 | TempFile tmpini{"TestIniTmp.ini"}; |
| 2460 | 2460 | |
| 2461 | 2461 | app.set_config("--config", tmpini); |
| 2462 | - auto ptr = app.set_config(); // Should *not* read config file | |
| 2462 | + auto *ptr = app.set_config(); // Should *not* read config file | |
| 2463 | 2463 | CHECK(nullptr == ptr); |
| 2464 | 2464 | |
| 2465 | 2465 | { |
| ... | ... | @@ -2618,7 +2618,7 @@ TEST_CASE_METHOD(TApp, "IniOutputMultiLineDescription", "[config]") { |
| 2618 | 2618 | TEST_CASE_METHOD(TApp, "IniOutputOptionGroupMultiLineDescription", "[config]") { |
| 2619 | 2619 | std::string flag = "flag"; |
| 2620 | 2620 | const std::string description = "Short flag description.\n"; |
| 2621 | - auto og = app.add_option_group("group"); | |
| 2621 | + auto *og = app.add_option_group("group"); | |
| 2622 | 2622 | og->description("Option group description.\n" |
| 2623 | 2623 | "That has multiple lines."); |
| 2624 | 2624 | og->add_flag("--" + flag, description); |
| ... | ... | @@ -2633,7 +2633,7 @@ TEST_CASE_METHOD(TApp, "IniOutputOptionGroupMultiLineDescription", "[config]") { |
| 2633 | 2633 | TEST_CASE_METHOD(TApp, "IniOutputSubcommandMultiLineDescription", "[config]") { |
| 2634 | 2634 | std::string flag = "flag"; |
| 2635 | 2635 | const std::string description = "Short flag description.\n"; |
| 2636 | - auto subcom = app.add_subcommand("subcommand"); | |
| 2636 | + auto *subcom = app.add_subcommand("subcommand"); | |
| 2637 | 2637 | subcom->configurable(); |
| 2638 | 2638 | subcom->description("Subcommand description.\n" |
| 2639 | 2639 | "That has multiple lines."); |
| ... | ... | @@ -2654,7 +2654,7 @@ TEST_CASE_METHOD(TApp, "IniOutputOptionGroup", "[config]") { |
| 2654 | 2654 | const std::string description2 = "Second description."; |
| 2655 | 2655 | app.add_flag("--" + flag1, description1)->group("group1"); |
| 2656 | 2656 | app.add_flag("--" + flag2, description2)->group("group2"); |
| 2657 | - auto og = app.add_option_group("group3", "g3 desc"); | |
| 2657 | + auto *og = app.add_option_group("group3", "g3 desc"); | |
| 2658 | 2658 | og->add_option("--dval", val)->capture_default_str()->group(""); |
| 2659 | 2659 | app.config_formatter(std::make_shared<CLI::ConfigINI>()); |
| 2660 | 2660 | run(); |
| ... | ... | @@ -2740,7 +2740,7 @@ TEST_CASE_METHOD(TApp, "IniOutputDefault", "[config]") { |
| 2740 | 2740 | TEST_CASE_METHOD(TApp, "IniOutputSubcom", "[config]") { |
| 2741 | 2741 | |
| 2742 | 2742 | app.add_flag("--simple"); |
| 2743 | - auto subcom = app.add_subcommand("other"); | |
| 2743 | + auto *subcom = app.add_subcommand("other"); | |
| 2744 | 2744 | subcom->add_flag("--newer"); |
| 2745 | 2745 | app.config_formatter(std::make_shared<CLI::ConfigINI>()); |
| 2746 | 2746 | args = {"--simple", "other", "--newer"}; |
| ... | ... | @@ -2754,7 +2754,7 @@ TEST_CASE_METHOD(TApp, "IniOutputSubcom", "[config]") { |
| 2754 | 2754 | TEST_CASE_METHOD(TApp, "IniOutputSubcomCustomSep", "[config]") { |
| 2755 | 2755 | |
| 2756 | 2756 | app.add_flag("--simple"); |
| 2757 | - auto subcom = app.add_subcommand("other"); | |
| 2757 | + auto *subcom = app.add_subcommand("other"); | |
| 2758 | 2758 | subcom->add_flag("--newer"); |
| 2759 | 2759 | app.config_formatter(std::make_shared<CLI::ConfigINI>()); |
| 2760 | 2760 | app.get_config_formatter_base()->parentSeparator(':'); |
| ... | ... | @@ -2769,7 +2769,7 @@ TEST_CASE_METHOD(TApp, "IniOutputSubcomCustomSep", "[config]") { |
| 2769 | 2769 | TEST_CASE_METHOD(TApp, "IniOutputSubcomConfigurable", "[config]") { |
| 2770 | 2770 | |
| 2771 | 2771 | app.add_flag("--simple"); |
| 2772 | - auto subcom = app.add_subcommand("other")->configurable(); | |
| 2772 | + auto *subcom = app.add_subcommand("other")->configurable(); | |
| 2773 | 2773 | subcom->add_flag("--newer"); |
| 2774 | 2774 | app.config_formatter(std::make_shared<CLI::ConfigINI>()); |
| 2775 | 2775 | args = {"--simple", "other", "--newer"}; |
| ... | ... | @@ -2785,9 +2785,9 @@ TEST_CASE_METHOD(TApp, "IniOutputSubcomConfigurable", "[config]") { |
| 2785 | 2785 | TEST_CASE_METHOD(TApp, "IniOutputSubsubcom", "[config]") { |
| 2786 | 2786 | |
| 2787 | 2787 | app.add_flag("--simple"); |
| 2788 | - auto subcom = app.add_subcommand("other"); | |
| 2788 | + auto *subcom = app.add_subcommand("other"); | |
| 2789 | 2789 | subcom->add_flag("--newer"); |
| 2790 | - auto subsubcom = subcom->add_subcommand("sub2"); | |
| 2790 | + auto *subsubcom = subcom->add_subcommand("sub2"); | |
| 2791 | 2791 | subsubcom->add_flag("--newest"); |
| 2792 | 2792 | app.config_formatter(std::make_shared<CLI::ConfigINI>()); |
| 2793 | 2793 | args = {"--simple", "other", "--newer", "sub2", "--newest"}; |
| ... | ... | @@ -2802,9 +2802,9 @@ TEST_CASE_METHOD(TApp, "IniOutputSubsubcom", "[config]") { |
| 2802 | 2802 | TEST_CASE_METHOD(TApp, "IniOutputSubsubcomCustomSep", "[config]") { |
| 2803 | 2803 | |
| 2804 | 2804 | app.add_flag("--simple"); |
| 2805 | - auto subcom = app.add_subcommand("other"); | |
| 2805 | + auto *subcom = app.add_subcommand("other"); | |
| 2806 | 2806 | subcom->add_flag("--newer"); |
| 2807 | - auto subsubcom = subcom->add_subcommand("sub2"); | |
| 2807 | + auto *subsubcom = subcom->add_subcommand("sub2"); | |
| 2808 | 2808 | subsubcom->add_flag("--newest"); |
| 2809 | 2809 | app.config_formatter(std::make_shared<CLI::ConfigINI>()); |
| 2810 | 2810 | app.get_config_formatter_base()->parentSeparator('|'); |
| ... | ... | @@ -2820,10 +2820,10 @@ TEST_CASE_METHOD(TApp, "IniOutputSubsubcomCustomSep", "[config]") { |
| 2820 | 2820 | TEST_CASE_METHOD(TApp, "IniOutputSubsubcomConfigurable", "[config]") { |
| 2821 | 2821 | |
| 2822 | 2822 | app.add_flag("--simple"); |
| 2823 | - auto subcom = app.add_subcommand("other")->configurable(); | |
| 2823 | + auto *subcom = app.add_subcommand("other")->configurable(); | |
| 2824 | 2824 | subcom->add_flag("--newer"); |
| 2825 | 2825 | |
| 2826 | - auto subsubcom = subcom->add_subcommand("sub2"); | |
| 2826 | + auto *subsubcom = subcom->add_subcommand("sub2"); | |
| 2827 | 2827 | subsubcom->add_flag("--newest"); |
| 2828 | 2828 | app.config_formatter(std::make_shared<CLI::ConfigINI>()); |
| 2829 | 2829 | args = {"--simple", "other", "--newer", "sub2", "--newest"}; |
| ... | ... | @@ -2841,14 +2841,14 @@ TEST_CASE_METHOD(TApp, "IniOutputSubsubcomConfigurable", "[config]") { |
| 2841 | 2841 | TEST_CASE_METHOD(TApp, "IniOutputSubsubcomConfigurableDeep", "[config]") { |
| 2842 | 2842 | |
| 2843 | 2843 | app.add_flag("--simple"); |
| 2844 | - auto subcom = app.add_subcommand("other")->configurable(); | |
| 2844 | + auto *subcom = app.add_subcommand("other")->configurable(); | |
| 2845 | 2845 | subcom->add_flag("--newer"); |
| 2846 | 2846 | |
| 2847 | - auto subsubcom = subcom->add_subcommand("sub2"); | |
| 2847 | + auto *subsubcom = subcom->add_subcommand("sub2"); | |
| 2848 | 2848 | subsubcom->add_flag("--newest"); |
| 2849 | - auto sssscom = subsubcom->add_subcommand("sub-level2"); | |
| 2849 | + auto *sssscom = subsubcom->add_subcommand("sub-level2"); | |
| 2850 | 2850 | subsubcom->add_flag("--still_newer"); |
| 2851 | - auto s5com = sssscom->add_subcommand("sub-level3"); | |
| 2851 | + auto *s5com = sssscom->add_subcommand("sub-level3"); | |
| 2852 | 2852 | s5com->add_flag("--absolute_newest"); |
| 2853 | 2853 | app.config_formatter(std::make_shared<CLI::ConfigINI>()); |
| 2854 | 2854 | args = {"--simple", "other", "sub2", "sub-level2", "sub-level3", "--absolute_newest"}; | ... | ... |
tests/CreationTest.cpp
| ... | ... | @@ -41,7 +41,7 @@ TEST_CASE_METHOD(TApp, "AddingExistingWithCase", "[creation]") { |
| 41 | 41 | } |
| 42 | 42 | |
| 43 | 43 | TEST_CASE_METHOD(TApp, "AddingExistingWithCaseAfter", "[creation]") { |
| 44 | - auto count = app.add_flag("-c,--count"); | |
| 44 | + auto *count = app.add_flag("-c,--count"); | |
| 45 | 45 | app.add_flag("--Cat,-C"); |
| 46 | 46 | |
| 47 | 47 | CHECK_THROWS_AS(count->ignore_case(), CLI::OptionAlreadyAdded); |
| ... | ... | @@ -49,20 +49,20 @@ TEST_CASE_METHOD(TApp, "AddingExistingWithCaseAfter", "[creation]") { |
| 49 | 49 | |
| 50 | 50 | TEST_CASE_METHOD(TApp, "AddingExistingWithCaseAfter2", "[creation]") { |
| 51 | 51 | app.add_flag("-c,--count"); |
| 52 | - auto cat = app.add_flag("--Cat,-C"); | |
| 52 | + auto *cat = app.add_flag("--Cat,-C"); | |
| 53 | 53 | |
| 54 | 54 | CHECK_THROWS_AS(cat->ignore_case(), CLI::OptionAlreadyAdded); |
| 55 | 55 | } |
| 56 | 56 | |
| 57 | 57 | TEST_CASE_METHOD(TApp, "AddingExistingWithUnderscoreAfter", "[creation]") { |
| 58 | - auto count = app.add_flag("--underscore"); | |
| 58 | + auto *count = app.add_flag("--underscore"); | |
| 59 | 59 | app.add_flag("--under_score"); |
| 60 | 60 | |
| 61 | 61 | CHECK_THROWS_AS(count->ignore_underscore(), CLI::OptionAlreadyAdded); |
| 62 | 62 | } |
| 63 | 63 | |
| 64 | 64 | TEST_CASE_METHOD(TApp, "AddingExistingWithUnderscoreAfter2", "[creation]") { |
| 65 | - auto count = app.add_flag("--under_score"); | |
| 65 | + auto *count = app.add_flag("--under_score"); | |
| 66 | 66 | app.add_flag("--underscore"); |
| 67 | 67 | |
| 68 | 68 | CHECK_THROWS_AS(count->ignore_underscore(), CLI::OptionAlreadyAdded); |
| ... | ... | @@ -125,13 +125,13 @@ TEST_CASE_METHOD(TApp, "MultipleSubcomMatchingWithUnderscoreFirst", "[creation]" |
| 125 | 125 | |
| 126 | 126 | TEST_CASE_METHOD(TApp, "MultipleSubcomMatchingWithCaseInplace", "[creation]") { |
| 127 | 127 | app.add_subcommand("first"); |
| 128 | - auto first = app.add_subcommand("fIrst"); | |
| 128 | + auto *first = app.add_subcommand("fIrst"); | |
| 129 | 129 | |
| 130 | 130 | CHECK_THROWS_AS(first->ignore_case(), CLI::OptionAlreadyAdded); |
| 131 | 131 | } |
| 132 | 132 | |
| 133 | 133 | TEST_CASE_METHOD(TApp, "MultipleSubcomMatchingWithCaseInplace2", "[creation]") { |
| 134 | - auto first = app.add_subcommand("first"); | |
| 134 | + auto *first = app.add_subcommand("first"); | |
| 135 | 135 | app.add_subcommand("fIrst"); |
| 136 | 136 | |
| 137 | 137 | CHECK_THROWS_AS(first->ignore_case(), CLI::OptionAlreadyAdded); |
| ... | ... | @@ -139,29 +139,29 @@ TEST_CASE_METHOD(TApp, "MultipleSubcomMatchingWithCaseInplace2", "[creation]") { |
| 139 | 139 | |
| 140 | 140 | TEST_CASE_METHOD(TApp, "MultipleSubcomMatchingWithUnderscoreInplace", "[creation]") { |
| 141 | 141 | app.add_subcommand("first_option"); |
| 142 | - auto first = app.add_subcommand("firstoption"); | |
| 142 | + auto *first = app.add_subcommand("firstoption"); | |
| 143 | 143 | |
| 144 | 144 | CHECK_THROWS_AS(first->ignore_underscore(), CLI::OptionAlreadyAdded); |
| 145 | 145 | } |
| 146 | 146 | |
| 147 | 147 | TEST_CASE_METHOD(TApp, "MultipleSubcomMatchingWithUnderscoreInplace2", "[creation]") { |
| 148 | - auto first = app.add_subcommand("firstoption"); | |
| 148 | + auto *first = app.add_subcommand("firstoption"); | |
| 149 | 149 | app.add_subcommand("first_option"); |
| 150 | 150 | |
| 151 | 151 | CHECK_THROWS_AS(first->ignore_underscore(), CLI::OptionAlreadyAdded); |
| 152 | 152 | } |
| 153 | 153 | |
| 154 | 154 | TEST_CASE_METHOD(TApp, "MultipleSubcomNoMatchingInplace2", "[creation]") { |
| 155 | - auto first = app.add_subcommand("first"); | |
| 156 | - auto second = app.add_subcommand("second"); | |
| 155 | + auto *first = app.add_subcommand("first"); | |
| 156 | + auto *second = app.add_subcommand("second"); | |
| 157 | 157 | |
| 158 | 158 | CHECK_NOTHROW(first->ignore_case()); |
| 159 | 159 | CHECK_NOTHROW(second->ignore_case()); |
| 160 | 160 | } |
| 161 | 161 | |
| 162 | 162 | TEST_CASE_METHOD(TApp, "MultipleSubcomNoMatchingInplaceUnderscore2", "[creation]") { |
| 163 | - auto first = app.add_subcommand("first_option"); | |
| 164 | - auto second = app.add_subcommand("second_option"); | |
| 163 | + auto *first = app.add_subcommand("first_option"); | |
| 164 | + auto *second = app.add_subcommand("second_option"); | |
| 165 | 165 | |
| 166 | 166 | CHECK_NOTHROW(first->ignore_underscore()); |
| 167 | 167 | CHECK_NOTHROW(second->ignore_underscore()); |
| ... | ... | @@ -183,25 +183,25 @@ TEST_CASE_METHOD(TApp, "IncorrectConstructionFlagPositional3", "[creation]") { |
| 183 | 183 | } |
| 184 | 184 | |
| 185 | 185 | TEST_CASE_METHOD(TApp, "IncorrectConstructionNeedsCannotFind", "[creation]") { |
| 186 | - auto cat = app.add_flag("--cat"); | |
| 186 | + auto *cat = app.add_flag("--cat"); | |
| 187 | 187 | CHECK_THROWS_AS(cat->needs("--nothing"), CLI::IncorrectConstruction); |
| 188 | 188 | } |
| 189 | 189 | |
| 190 | 190 | TEST_CASE_METHOD(TApp, "IncorrectConstructionExcludesCannotFind", "[creation]") { |
| 191 | - auto cat = app.add_flag("--cat"); | |
| 191 | + auto *cat = app.add_flag("--cat"); | |
| 192 | 192 | CHECK_THROWS_AS(cat->excludes("--nothing"), CLI::IncorrectConstruction); |
| 193 | 193 | } |
| 194 | 194 | |
| 195 | 195 | TEST_CASE_METHOD(TApp, "IncorrectConstructionDuplicateNeeds", "[creation]") { |
| 196 | - auto cat = app.add_flag("--cat"); | |
| 197 | - auto other = app.add_flag("--other"); | |
| 196 | + auto *cat = app.add_flag("--cat"); | |
| 197 | + auto *other = app.add_flag("--other"); | |
| 198 | 198 | REQUIRE_NOTHROW(cat->needs(other)); |
| 199 | 199 | // duplicated needs is redundant but not an error |
| 200 | 200 | CHECK_NOTHROW(cat->needs(other)); |
| 201 | 201 | } |
| 202 | 202 | |
| 203 | 203 | TEST_CASE_METHOD(TApp, "IncorrectConstructionDuplicateNeedsTxt", "[creation]") { |
| 204 | - auto cat = app.add_flag("--cat"); | |
| 204 | + auto *cat = app.add_flag("--cat"); | |
| 205 | 205 | app.add_flag("--other"); |
| 206 | 206 | REQUIRE_NOTHROW(cat->needs("--other")); |
| 207 | 207 | // duplicate needs is redundant but not an error |
| ... | ... | @@ -210,28 +210,28 @@ TEST_CASE_METHOD(TApp, "IncorrectConstructionDuplicateNeedsTxt", "[creation]") { |
| 210 | 210 | |
| 211 | 211 | // Now allowed |
| 212 | 212 | TEST_CASE_METHOD(TApp, "CorrectConstructionDuplicateExcludes", "[creation]") { |
| 213 | - auto cat = app.add_flag("--cat"); | |
| 214 | - auto other = app.add_flag("--other"); | |
| 213 | + auto *cat = app.add_flag("--cat"); | |
| 214 | + auto *other = app.add_flag("--other"); | |
| 215 | 215 | REQUIRE_NOTHROW(cat->excludes(other)); |
| 216 | 216 | REQUIRE_NOTHROW(other->excludes(cat)); |
| 217 | 217 | } |
| 218 | 218 | |
| 219 | 219 | // Now allowed |
| 220 | 220 | TEST_CASE_METHOD(TApp, "CorrectConstructionDuplicateExcludesTxt", "[creation]") { |
| 221 | - auto cat = app.add_flag("--cat"); | |
| 222 | - auto other = app.add_flag("--other"); | |
| 221 | + auto *cat = app.add_flag("--cat"); | |
| 222 | + auto *other = app.add_flag("--other"); | |
| 223 | 223 | REQUIRE_NOTHROW(cat->excludes("--other")); |
| 224 | 224 | REQUIRE_NOTHROW(other->excludes("--cat")); |
| 225 | 225 | } |
| 226 | 226 | |
| 227 | 227 | TEST_CASE_METHOD(TApp, "CheckName", "[creation]") { |
| 228 | - auto long1 = app.add_flag("--long1"); | |
| 229 | - auto long2 = app.add_flag("--Long2"); | |
| 230 | - auto short1 = app.add_flag("-a"); | |
| 231 | - auto short2 = app.add_flag("-B"); | |
| 228 | + auto *long1 = app.add_flag("--long1"); | |
| 229 | + auto *long2 = app.add_flag("--Long2"); | |
| 230 | + auto *short1 = app.add_flag("-a"); | |
| 231 | + auto *short2 = app.add_flag("-B"); | |
| 232 | 232 | int x{0}, y{0}; |
| 233 | - auto pos1 = app.add_option("pos1", x); | |
| 234 | - auto pos2 = app.add_option("pOs2", y); | |
| 233 | + auto *pos1 = app.add_option("pos1", x); | |
| 234 | + auto *pos2 = app.add_option("pOs2", y); | |
| 235 | 235 | |
| 236 | 236 | CHECK(long1->check_name("--long1")); |
| 237 | 237 | CHECK(!long1->check_name("--lonG1")); |
| ... | ... | @@ -253,13 +253,13 @@ TEST_CASE_METHOD(TApp, "CheckName", "[creation]") { |
| 253 | 253 | } |
| 254 | 254 | |
| 255 | 255 | TEST_CASE_METHOD(TApp, "CheckNameNoCase", "[creation]") { |
| 256 | - auto long1 = app.add_flag("--long1")->ignore_case(); | |
| 257 | - auto long2 = app.add_flag("--Long2")->ignore_case(); | |
| 258 | - auto short1 = app.add_flag("-a")->ignore_case(); | |
| 259 | - auto short2 = app.add_flag("-B")->ignore_case(); | |
| 256 | + auto *long1 = app.add_flag("--long1")->ignore_case(); | |
| 257 | + auto *long2 = app.add_flag("--Long2")->ignore_case(); | |
| 258 | + auto *short1 = app.add_flag("-a")->ignore_case(); | |
| 259 | + auto *short2 = app.add_flag("-B")->ignore_case(); | |
| 260 | 260 | int x{0}, y{0}; |
| 261 | - auto pos1 = app.add_option("pos1", x)->ignore_case(); | |
| 262 | - auto pos2 = app.add_option("pOs2", y)->ignore_case(); | |
| 261 | + auto *pos1 = app.add_option("pos1", x)->ignore_case(); | |
| 262 | + auto *pos2 = app.add_option("pOs2", y)->ignore_case(); | |
| 263 | 263 | |
| 264 | 264 | CHECK(long1->check_name("--long1")); |
| 265 | 265 | CHECK(long1->check_name("--lonG1")); |
| ... | ... | @@ -281,12 +281,12 @@ TEST_CASE_METHOD(TApp, "CheckNameNoCase", "[creation]") { |
| 281 | 281 | } |
| 282 | 282 | |
| 283 | 283 | TEST_CASE_METHOD(TApp, "CheckNameNoUnderscore", "[creation]") { |
| 284 | - auto long1 = app.add_flag("--longoption1")->ignore_underscore(); | |
| 285 | - auto long2 = app.add_flag("--long_option2")->ignore_underscore(); | |
| 284 | + auto *long1 = app.add_flag("--longoption1")->ignore_underscore(); | |
| 285 | + auto *long2 = app.add_flag("--long_option2")->ignore_underscore(); | |
| 286 | 286 | |
| 287 | 287 | int x{0}, y{0}; |
| 288 | - auto pos1 = app.add_option("pos_option_1", x)->ignore_underscore(); | |
| 289 | - auto pos2 = app.add_option("posoption2", y)->ignore_underscore(); | |
| 288 | + auto *pos1 = app.add_option("pos_option_1", x)->ignore_underscore(); | |
| 289 | + auto *pos2 = app.add_option("posoption2", y)->ignore_underscore(); | |
| 290 | 290 | |
| 291 | 291 | CHECK(long1->check_name("--long_option1")); |
| 292 | 292 | CHECK(long1->check_name("--longoption_1")); |
| ... | ... | @@ -312,12 +312,12 @@ TEST_CASE_METHOD(TApp, "CheckNameNoUnderscore", "[creation]") { |
| 312 | 312 | } |
| 313 | 313 | |
| 314 | 314 | TEST_CASE_METHOD(TApp, "CheckNameNoCaseNoUnderscore", "[creation]") { |
| 315 | - auto long1 = app.add_flag("--LongoptioN1")->ignore_underscore()->ignore_case(); | |
| 316 | - auto long2 = app.add_flag("--long_Option2")->ignore_case()->ignore_underscore(); | |
| 315 | + auto *long1 = app.add_flag("--LongoptioN1")->ignore_underscore()->ignore_case(); | |
| 316 | + auto *long2 = app.add_flag("--long_Option2")->ignore_case()->ignore_underscore(); | |
| 317 | 317 | |
| 318 | 318 | int x{0}, y{0}; |
| 319 | - auto pos1 = app.add_option("pos_Option_1", x)->ignore_underscore()->ignore_case(); | |
| 320 | - auto pos2 = app.add_option("posOption2", y)->ignore_case()->ignore_underscore(); | |
| 319 | + auto *pos1 = app.add_option("pos_Option_1", x)->ignore_underscore()->ignore_case(); | |
| 320 | + auto *pos2 = app.add_option("posOption2", y)->ignore_case()->ignore_underscore(); | |
| 321 | 321 | |
| 322 | 322 | CHECK(long1->check_name("--Long_Option1")); |
| 323 | 323 | CHECK(long1->check_name("--lONgoption_1")); |
| ... | ... | @@ -344,7 +344,7 @@ TEST_CASE_METHOD(TApp, "CheckNameNoCaseNoUnderscore", "[creation]") { |
| 344 | 344 | |
| 345 | 345 | TEST_CASE_METHOD(TApp, "PreSpaces", "[creation]") { |
| 346 | 346 | int x{0}; |
| 347 | - auto myapp = app.add_option(" -a, --long, other", x); | |
| 347 | + auto *myapp = app.add_option(" -a, --long, other", x); | |
| 348 | 348 | |
| 349 | 349 | CHECK(myapp->check_lname("long")); |
| 350 | 350 | CHECK(myapp->check_sname("a")); |
| ... | ... | @@ -353,7 +353,7 @@ TEST_CASE_METHOD(TApp, "PreSpaces", "[creation]") { |
| 353 | 353 | |
| 354 | 354 | TEST_CASE_METHOD(TApp, "AllSpaces", "[creation]") { |
| 355 | 355 | int x{0}; |
| 356 | - auto myapp = app.add_option(" -a , --long , other ", x); | |
| 356 | + auto *myapp = app.add_option(" -a , --long , other ", x); | |
| 357 | 357 | |
| 358 | 358 | CHECK(myapp->check_lname("long")); |
| 359 | 359 | CHECK(myapp->check_sname("a")); |
| ... | ... | @@ -365,26 +365,26 @@ TEST_CASE_METHOD(TApp, "OptionFromDefaults", "[creation]") { |
| 365 | 365 | |
| 366 | 366 | // Options should remember defaults |
| 367 | 367 | int x{0}; |
| 368 | - auto opt = app.add_option("--simple", x); | |
| 368 | + auto *opt = app.add_option("--simple", x); | |
| 369 | 369 | CHECK(opt->get_required()); |
| 370 | 370 | |
| 371 | 371 | // Flags cannot be required |
| 372 | - auto flag = app.add_flag("--other"); | |
| 372 | + auto *flag = app.add_flag("--other"); | |
| 373 | 373 | CHECK(!flag->get_required()); |
| 374 | 374 | |
| 375 | 375 | app.option_defaults()->required(false); |
| 376 | - auto opt2 = app.add_option("--simple2", x); | |
| 376 | + auto *opt2 = app.add_option("--simple2", x); | |
| 377 | 377 | CHECK(!opt2->get_required()); |
| 378 | 378 | |
| 379 | 379 | app.option_defaults()->required()->ignore_case(); |
| 380 | 380 | |
| 381 | - auto opt3 = app.add_option("--simple3", x); | |
| 381 | + auto *opt3 = app.add_option("--simple3", x); | |
| 382 | 382 | CHECK(opt3->get_required()); |
| 383 | 383 | CHECK(opt3->get_ignore_case()); |
| 384 | 384 | |
| 385 | 385 | app.option_defaults()->required()->ignore_underscore(); |
| 386 | 386 | |
| 387 | - auto opt4 = app.add_option("--simple4", x); | |
| 387 | + auto *opt4 = app.add_option("--simple4", x); | |
| 388 | 388 | CHECK(opt4->get_required()); |
| 389 | 389 | CHECK(opt4->get_ignore_underscore()); |
| 390 | 390 | } |
| ... | ... | @@ -408,7 +408,7 @@ TEST_CASE_METHOD(TApp, "OptionFromDefaultsSubcommands", "[creation]") { |
| 408 | 408 | ->disable_flag_override() |
| 409 | 409 | ->group("Something"); |
| 410 | 410 | |
| 411 | - auto app2 = app.add_subcommand("app2"); | |
| 411 | + auto *app2 = app.add_subcommand("app2"); | |
| 412 | 412 | |
| 413 | 413 | CHECK(app2->option_defaults()->get_required()); |
| 414 | 414 | CHECK(CLI::MultiOptionPolicy::TakeLast == app2->option_defaults()->get_multi_option_policy()); |
| ... | ... | @@ -421,10 +421,10 @@ TEST_CASE_METHOD(TApp, "OptionFromDefaultsSubcommands", "[creation]") { |
| 421 | 421 | |
| 422 | 422 | TEST_CASE_METHOD(TApp, "GetNameCheck", "[creation]") { |
| 423 | 423 | int x{0}; |
| 424 | - auto a = app.add_flag("--that"); | |
| 425 | - auto b = app.add_flag("-x"); | |
| 426 | - auto c = app.add_option("pos", x); | |
| 427 | - auto d = app.add_option("one,-o,--other", x); | |
| 424 | + auto *a = app.add_flag("--that"); | |
| 425 | + auto *b = app.add_flag("-x"); | |
| 426 | + auto *c = app.add_option("pos", x); | |
| 427 | + auto *d = app.add_option("one,-o,--other", x); | |
| 428 | 428 | |
| 429 | 429 | CHECK("--that" == a->get_name(false, true)); |
| 430 | 430 | CHECK("-x" == b->get_name(false, true)); |
| ... | ... | @@ -455,7 +455,7 @@ TEST_CASE_METHOD(TApp, "SubcommandDefaults", "[creation]") { |
| 455 | 455 | CHECK(!app.get_configurable()); |
| 456 | 456 | CHECK(!app.get_validate_positionals()); |
| 457 | 457 | |
| 458 | - CHECK("" == app.get_footer()); | |
| 458 | + CHECK(app.get_footer().empty()); | |
| 459 | 459 | CHECK("Subcommands" == app.get_group()); |
| 460 | 460 | CHECK(0u == app.get_require_subcommand_min()); |
| 461 | 461 | CHECK(0u == app.get_require_subcommand_max()); |
| ... | ... | @@ -478,7 +478,7 @@ TEST_CASE_METHOD(TApp, "SubcommandDefaults", "[creation]") { |
| 478 | 478 | app.group("Stuff"); |
| 479 | 479 | app.require_subcommand(2, 3); |
| 480 | 480 | |
| 481 | - auto app2 = app.add_subcommand("app2"); | |
| 481 | + auto *app2 = app.add_subcommand("app2"); | |
| 482 | 482 | |
| 483 | 483 | // Initial defaults |
| 484 | 484 | CHECK(app2->get_allow_extras()); |
| ... | ... | @@ -533,8 +533,8 @@ TEST_CASE_METHOD(TApp, "SubcommandMinMax", "[creation]") { |
| 533 | 533 | |
| 534 | 534 | TEST_CASE_METHOD(TApp, "GetOptionList", "[creation]") { |
| 535 | 535 | int two{0}; |
| 536 | - auto flag = app.add_flag("--one"); | |
| 537 | - auto opt = app.add_option("--two", two); | |
| 536 | + auto *flag = app.add_flag("--one"); | |
| 537 | + auto *opt = app.add_option("--two", two); | |
| 538 | 538 | |
| 539 | 539 | const CLI::App &const_app = app; // const alias to force use of const-methods |
| 540 | 540 | std::vector<const CLI::Option *> opt_list = const_app.get_options(); |
| ... | ... | @@ -561,9 +561,9 @@ TEST_CASE("ValidatorTests: TestValidatorCreation", "[creation]") { |
| 561 | 561 | CHECK(V.get_active()); |
| 562 | 562 | |
| 563 | 563 | CHECK("test" == V("test")); |
| 564 | - CHECK(std::string{} == V("test5")); | |
| 564 | + CHECK(V("test5").empty()); | |
| 565 | 565 | |
| 566 | - CHECK(std::string{} == V.get_description()); | |
| 566 | + CHECK(V.get_description().empty()); | |
| 567 | 567 | V.description("this is a description"); |
| 568 | 568 | CHECK("this is a description" == V.get_description()); |
| 569 | 569 | } |
| ... | ... | @@ -717,7 +717,7 @@ class Unstreamable { |
| 717 | 717 | |
| 718 | 718 | public: |
| 719 | 719 | Unstreamable() = default; |
| 720 | - int get_x() const { return x_; } | |
| 720 | + CLI11_NODISCARD int get_x() const { return x_; } | |
| 721 | 721 | void set_x(int x) { x_ = x; } |
| 722 | 722 | }; |
| 723 | 723 | |
| ... | ... | @@ -725,7 +725,7 @@ class Unstreamable { |
| 725 | 725 | static_assert(!CLI::detail::is_istreamable<Unstreamable, std::istream>::value, "Unstreamable type is streamable"); |
| 726 | 726 | |
| 727 | 727 | std::istream &operator>>(std::istream &in, Unstreamable &value) { |
| 728 | - int x; | |
| 728 | + int x = 0; | |
| 729 | 729 | in >> x; |
| 730 | 730 | value.set_x(x); |
| 731 | 731 | return in; | ... | ... |
tests/HelpTest.cpp
| ... | ... | @@ -105,7 +105,7 @@ TEST_CASE("THelp: deprecatedOptions", "[help]") { |
| 105 | 105 | CLI::App app{"My prog"}; |
| 106 | 106 | |
| 107 | 107 | std::string x; |
| 108 | - auto soption = app.add_option("--something", x, "My option here"); | |
| 108 | + auto *soption = app.add_option("--something", x, "My option here"); | |
| 109 | 109 | app.add_option("--something_else", x, "My option here"); |
| 110 | 110 | std::string y; |
| 111 | 111 | app.add_option("--another", y); |
| ... | ... | @@ -159,7 +159,7 @@ TEST_CASE("THelp: retiredOptions", "[help]") { |
| 159 | 159 | CLI::App app{"My prog"}; |
| 160 | 160 | |
| 161 | 161 | std::string x; |
| 162 | - auto opt1 = app.add_option("--something", x, "My option here"); | |
| 162 | + auto *opt1 = app.add_option("--something", x, "My option here"); | |
| 163 | 163 | app.add_option("--something_else", x, "My option here"); |
| 164 | 164 | std::string y; |
| 165 | 165 | app.add_option("--another", y); |
| ... | ... | @@ -213,7 +213,7 @@ TEST_CASE("THelp: retiredOptions3", "[help]") { |
| 213 | 213 | TEST_CASE("THelp: HiddenGroup", "[help]") { |
| 214 | 214 | CLI::App app{"My prog"}; |
| 215 | 215 | // empty option group name should be hidden |
| 216 | - auto hgroup = app.add_option_group(""); | |
| 216 | + auto *hgroup = app.add_option_group(""); | |
| 217 | 217 | std::string x; |
| 218 | 218 | hgroup->add_option("something", x, "My option here"); |
| 219 | 219 | std::string y; |
| ... | ... | @@ -442,7 +442,7 @@ TEST_CASE("THelp: ManualSetterOverFunction", "[help]") { |
| 442 | 442 | TEST_CASE("THelp: Subcom", "[help]") { |
| 443 | 443 | CLI::App app{"My prog"}; |
| 444 | 444 | |
| 445 | - auto sub1 = app.add_subcommand("sub1"); | |
| 445 | + auto *sub1 = app.add_subcommand("sub1"); | |
| 446 | 446 | app.add_subcommand("sub2"); |
| 447 | 447 | |
| 448 | 448 | std::string help = app.help(); |
| ... | ... | @@ -456,8 +456,8 @@ TEST_CASE("THelp: Subcom", "[help]") { |
| 456 | 456 | help = sub1->help(); |
| 457 | 457 | CHECK_THAT(help, Contains("Usage: sub1")); |
| 458 | 458 | |
| 459 | - char x[] = "./myprogram"; | |
| 460 | - char y[] = "sub2"; | |
| 459 | + char x[] = "./myprogram"; // NOLINT(modernize-avoid-c-arrays) | |
| 460 | + char y[] = "sub2"; // NOLINT(modernize-avoid-c-arrays) | |
| 461 | 461 | |
| 462 | 462 | std::vector<char *> args = {x, y}; |
| 463 | 463 | app.parse(static_cast<int>(args.size()), args.data()); |
| ... | ... | @@ -469,7 +469,7 @@ TEST_CASE("THelp: Subcom", "[help]") { |
| 469 | 469 | TEST_CASE("THelp: Subcom_alias", "[help]") { |
| 470 | 470 | CLI::App app{"My prog"}; |
| 471 | 471 | |
| 472 | - auto sub1 = app.add_subcommand("sub1", "Subcommand1 description test"); | |
| 472 | + auto *sub1 = app.add_subcommand("sub1", "Subcommand1 description test"); | |
| 473 | 473 | sub1->alias("sub_alias1"); |
| 474 | 474 | sub1->alias("sub_alias2"); |
| 475 | 475 | |
| ... | ... | @@ -484,7 +484,7 @@ TEST_CASE("THelp: Subcom_alias", "[help]") { |
| 484 | 484 | TEST_CASE("THelp: Subcom_alias_group", "[help]") { |
| 485 | 485 | CLI::App app{"My prog"}; |
| 486 | 486 | |
| 487 | - auto sub1 = app.add_subcommand("", "Subcommand1 description test"); | |
| 487 | + auto *sub1 = app.add_subcommand("", "Subcommand1 description test"); | |
| 488 | 488 | sub1->alias("sub_alias1"); |
| 489 | 489 | sub1->alias("sub_alias2"); |
| 490 | 490 | |
| ... | ... | @@ -499,7 +499,7 @@ TEST_CASE("THelp: Subcom_alias_group", "[help]") { |
| 499 | 499 | TEST_CASE("THelp: MasterName", "[help]") { |
| 500 | 500 | CLI::App app{"My prog", "MyRealName"}; |
| 501 | 501 | |
| 502 | - char x[] = "./myprogram"; | |
| 502 | + char x[] = "./myprogram"; // NOLINT(modernize-avoid-c-arrays) | |
| 503 | 503 | |
| 504 | 504 | std::vector<char *> args = {x}; |
| 505 | 505 | app.parse(static_cast<int>(args.size()), args.data()); |
| ... | ... | @@ -699,9 +699,9 @@ TEST_CASE("THelp: NiceName", "[help]") { |
| 699 | 699 | CLI::App app; |
| 700 | 700 | |
| 701 | 701 | int x{0}; |
| 702 | - auto long_name = app.add_option("-s,--long,-q,--other,that", x); | |
| 703 | - auto short_name = app.add_option("more,-x,-y", x); | |
| 704 | - auto positional = app.add_option("posit", x); | |
| 702 | + auto *long_name = app.add_option("-s,--long,-q,--other,that", x); | |
| 703 | + auto *short_name = app.add_option("more,-x,-y", x); | |
| 704 | + auto *positional = app.add_option("posit", x); | |
| 705 | 705 | |
| 706 | 706 | CHECK("--long" == long_name->get_name()); |
| 707 | 707 | CHECK("-x" == short_name->get_name()); |
| ... | ... | @@ -768,25 +768,25 @@ struct CapturedHelp { |
| 768 | 768 | |
| 769 | 769 | TEST_CASE_METHOD(CapturedHelp, "Successful", "[help]") { |
| 770 | 770 | CHECK(0 == run(CLI::Success())); |
| 771 | - CHECK("" == out.str()); | |
| 772 | - CHECK("" == err.str()); | |
| 771 | + CHECK(out.str().empty()); | |
| 772 | + CHECK(err.str().empty()); | |
| 773 | 773 | } |
| 774 | 774 | |
| 775 | 775 | TEST_CASE_METHOD(CapturedHelp, "JustAnError", "[help]") { |
| 776 | 776 | CHECK(42 == run(CLI::RuntimeError(42))); |
| 777 | - CHECK("" == out.str()); | |
| 778 | - CHECK("" == err.str()); | |
| 777 | + CHECK(out.str().empty()); | |
| 778 | + CHECK(err.str().empty()); | |
| 779 | 779 | } |
| 780 | 780 | |
| 781 | 781 | TEST_CASE_METHOD(CapturedHelp, "CallForHelp", "[help]") { |
| 782 | 782 | CHECK(0 == run(CLI::CallForHelp())); |
| 783 | 783 | CHECK(app.help() == out.str()); |
| 784 | - CHECK("" == err.str()); | |
| 784 | + CHECK(err.str().empty()); | |
| 785 | 785 | } |
| 786 | 786 | TEST_CASE_METHOD(CapturedHelp, "CallForAllHelp", "[help]") { |
| 787 | 787 | CHECK(0 == run(CLI::CallForAllHelp())); |
| 788 | 788 | CHECK(app.help("", CLI::AppFormatMode::All) == out.str()); |
| 789 | - CHECK("" == err.str()); | |
| 789 | + CHECK(err.str().empty()); | |
| 790 | 790 | } |
| 791 | 791 | TEST_CASE_METHOD(CapturedHelp, "CallForAllHelpOutput", "[help]") { |
| 792 | 792 | app.set_help_all_flag("--help-all", "Help all"); |
| ... | ... | @@ -796,7 +796,7 @@ TEST_CASE_METHOD(CapturedHelp, "CallForAllHelpOutput", "[help]") { |
| 796 | 796 | |
| 797 | 797 | CHECK(0 == run(CLI::CallForAllHelp())); |
| 798 | 798 | CHECK(app.help("", CLI::AppFormatMode::All) == out.str()); |
| 799 | - CHECK("" == err.str()); | |
| 799 | + CHECK(err.str().empty()); | |
| 800 | 800 | CHECK_THAT(out.str(), Contains("one")); |
| 801 | 801 | CHECK_THAT(out.str(), Contains("two")); |
| 802 | 802 | CHECK_THAT(out.str(), Contains("--three")); |
| ... | ... | @@ -819,12 +819,12 @@ TEST_CASE_METHOD(CapturedHelp, "NewFormattedHelp", "[help]") { |
| 819 | 819 | app.formatter_fn([](const CLI::App *, std::string, CLI::AppFormatMode) { return "New Help"; }); |
| 820 | 820 | CHECK(0 == run(CLI::CallForHelp())); |
| 821 | 821 | CHECK("New Help" == out.str()); |
| 822 | - CHECK("" == err.str()); | |
| 822 | + CHECK(err.str().empty()); | |
| 823 | 823 | } |
| 824 | 824 | |
| 825 | 825 | TEST_CASE_METHOD(CapturedHelp, "NormalError", "[help]") { |
| 826 | 826 | CHECK(static_cast<int>(CLI::ExitCodes::ExtrasError) == run(CLI::ExtrasError({"Thing"}))); |
| 827 | - CHECK("" == out.str()); | |
| 827 | + CHECK(out.str().empty()); | |
| 828 | 828 | CHECK_THAT(err.str(), Contains("for more information")); |
| 829 | 829 | CHECK_THAT(err.str(), !Contains("ExtrasError")); |
| 830 | 830 | CHECK_THAT(err.str(), Contains("Thing")); |
| ... | ... | @@ -835,7 +835,7 @@ TEST_CASE_METHOD(CapturedHelp, "NormalError", "[help]") { |
| 835 | 835 | TEST_CASE_METHOD(CapturedHelp, "DoubleError", "[help]") { |
| 836 | 836 | app.set_help_all_flag("--help-all"); |
| 837 | 837 | CHECK(static_cast<int>(CLI::ExitCodes::ExtrasError) == run(CLI::ExtrasError({"Thing"}))); |
| 838 | - CHECK("" == out.str()); | |
| 838 | + CHECK(out.str().empty()); | |
| 839 | 839 | CHECK_THAT(err.str(), Contains("for more information")); |
| 840 | 840 | CHECK_THAT(err.str(), Contains(" --help ")); |
| 841 | 841 | CHECK_THAT(err.str(), Contains(" --help-all ")); |
| ... | ... | @@ -849,7 +849,7 @@ TEST_CASE_METHOD(CapturedHelp, "AllOnlyError", "[help]") { |
| 849 | 849 | app.set_help_all_flag("--help-all"); |
| 850 | 850 | app.set_help_flag(); |
| 851 | 851 | CHECK(static_cast<int>(CLI::ExitCodes::ExtrasError) == run(CLI::ExtrasError({"Thing"}))); |
| 852 | - CHECK("" == out.str()); | |
| 852 | + CHECK(out.str().empty()); | |
| 853 | 853 | CHECK_THAT(err.str(), Contains("for more information")); |
| 854 | 854 | CHECK_THAT(err.str(), !Contains(" --help ")); |
| 855 | 855 | CHECK_THAT(err.str(), Contains(" --help-all ")); |
| ... | ... | @@ -863,7 +863,7 @@ TEST_CASE_METHOD(CapturedHelp, "ReplacedError", "[help]") { |
| 863 | 863 | app.failure_message(CLI::FailureMessage::help); |
| 864 | 864 | |
| 865 | 865 | CHECK(static_cast<int>(CLI::ExitCodes::ExtrasError) == run(CLI::ExtrasError({"Thing"}))); |
| 866 | - CHECK("" == out.str()); | |
| 866 | + CHECK(out.str().empty()); | |
| 867 | 867 | CHECK_THAT(err.str(), !Contains("for more information")); |
| 868 | 868 | CHECK_THAT(err.str(), Contains("ERROR: ExtrasError")); |
| 869 | 869 | CHECK_THAT(err.str(), Contains("Thing")); |
| ... | ... | @@ -877,7 +877,7 @@ TEST_CASE("THelp: CustomDoubleOption", "[help]") { |
| 877 | 877 | |
| 878 | 878 | CLI::App app; |
| 879 | 879 | |
| 880 | - auto opt = app.add_option("posit", [&custom_opt](CLI::results_t vals) { | |
| 880 | + auto *opt = app.add_option("posit", [&custom_opt](CLI::results_t vals) { | |
| 881 | 881 | custom_opt = {stol(vals.at(0)), stod(vals.at(1))}; |
| 882 | 882 | return true; |
| 883 | 883 | }); |
| ... | ... | @@ -889,7 +889,7 @@ TEST_CASE("THelp: CustomDoubleOption", "[help]") { |
| 889 | 889 | TEST_CASE("THelp: CheckEmptyTypeName", "[help]") { |
| 890 | 890 | CLI::App app; |
| 891 | 891 | |
| 892 | - auto opt = app.add_flag("-f,--flag"); | |
| 892 | + auto *opt = app.add_flag("-f,--flag"); | |
| 893 | 893 | std::string name = opt->get_type_name(); |
| 894 | 894 | CHECK(name.empty()); |
| 895 | 895 | } |
| ... | ... | @@ -921,7 +921,7 @@ TEST_CASE("THelp: AccessOptionDescription", "[help]") { |
| 921 | 921 | CLI::App app{}; |
| 922 | 922 | |
| 923 | 923 | int x{0}; |
| 924 | - auto opt = app.add_option("-a,--alpha", x, "My description goes here"); | |
| 924 | + auto *opt = app.add_option("-a,--alpha", x, "My description goes here"); | |
| 925 | 925 | |
| 926 | 926 | CHECK("My description goes here" == opt->get_description()); |
| 927 | 927 | } |
| ... | ... | @@ -930,7 +930,7 @@ TEST_CASE("THelp: SetOptionDescriptionAfterCreation", "[help]") { |
| 930 | 930 | CLI::App app{}; |
| 931 | 931 | |
| 932 | 932 | int x{0}; |
| 933 | - auto opt = app.add_option("-a,--alpha", x); | |
| 933 | + auto *opt = app.add_option("-a,--alpha", x); | |
| 934 | 934 | opt->description("My description goes here"); |
| 935 | 935 | |
| 936 | 936 | CHECK("My description goes here" == opt->get_description()); |
| ... | ... | @@ -941,7 +941,7 @@ TEST_CASE("THelp: CleanNeeds", "[help]") { |
| 941 | 941 | CLI::App app; |
| 942 | 942 | |
| 943 | 943 | int x{0}; |
| 944 | - auto a_name = app.add_option("-a,--alpha", x); | |
| 944 | + auto *a_name = app.add_option("-a,--alpha", x); | |
| 945 | 945 | app.add_option("-b,--boo", x)->needs(a_name); |
| 946 | 946 | |
| 947 | 947 | CHECK_THAT(app.help(), !Contains("Requires")); |
| ... | ... | @@ -1260,7 +1260,7 @@ TEST_CASE("TVersion: parse_throw", "[help]") { |
| 1260 | 1260 | CHECK_THROWS_AS(app.parse("--version"), CLI::CallForVersion); |
| 1261 | 1261 | CHECK_THROWS_AS(app.parse("--version --arg2 5"), CLI::CallForVersion); |
| 1262 | 1262 | |
| 1263 | - auto ptr = app.get_version_ptr(); | |
| 1263 | + auto *ptr = app.get_version_ptr(); | |
| 1264 | 1264 | |
| 1265 | 1265 | ptr->ignore_case(); |
| 1266 | 1266 | try { |
| ... | ... | @@ -1269,7 +1269,7 @@ TEST_CASE("TVersion: parse_throw", "[help]") { |
| 1269 | 1269 | CHECK_THAT(CLI11_VERSION, Catch::Equals(v.what())); |
| 1270 | 1270 | CHECK(0 == v.get_exit_code()); |
| 1271 | 1271 | const auto &appc = app; |
| 1272 | - auto cptr = appc.get_version_ptr(); | |
| 1272 | + const auto *cptr = appc.get_version_ptr(); | |
| 1273 | 1273 | CHECK(1U == cptr->count()); |
| 1274 | 1274 | } |
| 1275 | 1275 | } | ... | ... |
tests/HelpersTest.cpp
| ... | ... | @@ -6,6 +6,8 @@ |
| 6 | 6 | |
| 7 | 7 | #include "app_helper.hpp" |
| 8 | 8 | |
| 9 | +#include <cmath> | |
| 10 | + | |
| 9 | 11 | #include <array> |
| 10 | 12 | #include <atomic> |
| 11 | 13 | #include <complex> |
| ... | ... | @@ -27,7 +29,7 @@ std::ostream &operator<<(std::ostream &out, const Streamable &) { return out << |
| 27 | 29 | |
| 28 | 30 | TEST_CASE("TypeTools: Streaming", "[helpers]") { |
| 29 | 31 | |
| 30 | - CHECK("" == CLI::detail::to_string(NotStreamable{})); | |
| 32 | + CHECK(CLI::detail::to_string(NotStreamable{}).empty()); | |
| 31 | 33 | |
| 32 | 34 | CHECK("Streamable" == CLI::detail::to_string(Streamable{})); |
| 33 | 35 | |
| ... | ... | @@ -148,7 +150,7 @@ TEST_CASE("Split: Single", "[helpers]") { |
| 148 | 150 | TEST_CASE("Split: Empty", "[helpers]") { |
| 149 | 151 | auto out = CLI::detail::split("", '.'); |
| 150 | 152 | REQUIRE(out.size() == 1u); |
| 151 | - CHECK(out.at(0) == ""); | |
| 153 | + CHECK(out.at(0).empty()); | |
| 152 | 154 | } |
| 153 | 155 | |
| 154 | 156 | TEST_CASE("String: InvalidName", "[helpers]") { |
| ... | ... | @@ -321,17 +323,17 @@ TEST_CASE("Validators: FilePathModifier", "[helpers]") { |
| 321 | 323 | |
| 322 | 324 | TEST_CASE("Validators: FileIsDir", "[helpers]") { |
| 323 | 325 | std::string mydir{"../tests"}; |
| 324 | - CHECK("" != CLI::ExistingFile(mydir)); | |
| 326 | + CHECK(!CLI::ExistingFile(mydir).empty()); | |
| 325 | 327 | } |
| 326 | 328 | |
| 327 | 329 | TEST_CASE("Validators: DirectoryExists", "[helpers]") { |
| 328 | 330 | std::string mydir{"../tests"}; |
| 329 | - CHECK("" == CLI::ExistingDirectory(mydir)); | |
| 331 | + CHECK(CLI::ExistingDirectory(mydir).empty()); | |
| 330 | 332 | } |
| 331 | 333 | |
| 332 | 334 | TEST_CASE("Validators: DirectoryNotExists", "[helpers]") { |
| 333 | 335 | std::string mydir{"nondirectory"}; |
| 334 | - CHECK("" != CLI::ExistingDirectory(mydir)); | |
| 336 | + CHECK(!CLI::ExistingDirectory(mydir).empty()); | |
| 335 | 337 | } |
| 336 | 338 | |
| 337 | 339 | TEST_CASE("Validators: DirectoryIsFile", "[helpers]") { |
| ... | ... | @@ -347,7 +349,7 @@ TEST_CASE("Validators: DirectoryIsFile", "[helpers]") { |
| 347 | 349 | |
| 348 | 350 | TEST_CASE("Validators: PathExistsDir", "[helpers]") { |
| 349 | 351 | std::string mydir{"../tests"}; |
| 350 | - CHECK("" == CLI::ExistingPath(mydir)); | |
| 352 | + CHECK(CLI::ExistingPath(mydir).empty()); | |
| 351 | 353 | } |
| 352 | 354 | |
| 353 | 355 | TEST_CASE("Validators: PathExistsFile", "[helpers]") { |
| ... | ... | @@ -363,7 +365,7 @@ TEST_CASE("Validators: PathExistsFile", "[helpers]") { |
| 363 | 365 | |
| 364 | 366 | TEST_CASE("Validators: PathNotExistsDir", "[helpers]") { |
| 365 | 367 | std::string mydir{"nonpath"}; |
| 366 | - CHECK("" != CLI::ExistingPath(mydir)); | |
| 368 | + CHECK(!CLI::ExistingPath(mydir).empty()); | |
| 367 | 369 | } |
| 368 | 370 | |
| 369 | 371 | TEST_CASE("Validators: IPValidate1", "[helpers]") { |
| ... | ... | @@ -701,15 +703,15 @@ TEST_CASE("CheckedMultiply: Double", "[helpers]") { |
| 701 | 703 | REQUIRE(CLI::detail::checked_multiply(a, b)); |
| 702 | 704 | REQUIRE(0 == Approx(a)); |
| 703 | 705 | |
| 704 | - a = INFINITY; | |
| 706 | + a = std::numeric_limits<double>::infinity(); | |
| 705 | 707 | b = 20; |
| 706 | 708 | REQUIRE(CLI::detail::checked_multiply(a, b)); |
| 707 | - REQUIRE(INFINITY == Approx(a)); | |
| 709 | + REQUIRE(std::numeric_limits<double>::infinity() == Approx(a)); | |
| 708 | 710 | |
| 709 | 711 | a = 2; |
| 710 | - b = -INFINITY; | |
| 712 | + b = -std::numeric_limits<double>::infinity(); | |
| 711 | 713 | REQUIRE(CLI::detail::checked_multiply(a, b)); |
| 712 | - REQUIRE(-INFINITY == Approx(a)); | |
| 714 | + REQUIRE(-std::numeric_limits<double>::infinity() == Approx(a)); | |
| 713 | 715 | |
| 714 | 716 | a = (std::numeric_limits<double>::max)() / 100; |
| 715 | 717 | b = 1; |
| ... | ... | @@ -795,11 +797,11 @@ TEST_CASE("RegEx: Shorts", "[helpers]") { |
| 795 | 797 | |
| 796 | 798 | CHECK(CLI::detail::split_short("-a", name, value)); |
| 797 | 799 | CHECK(name == "a"); |
| 798 | - CHECK(value == ""); | |
| 800 | + CHECK(value.empty()); | |
| 799 | 801 | |
| 800 | 802 | CHECK(CLI::detail::split_short("-B", name, value)); |
| 801 | 803 | CHECK(name == "B"); |
| 802 | - CHECK(value == ""); | |
| 804 | + CHECK(value.empty()); | |
| 803 | 805 | |
| 804 | 806 | CHECK(CLI::detail::split_short("-cc", name, value)); |
| 805 | 807 | CHECK(name == "c"); |
| ... | ... | @@ -821,11 +823,11 @@ TEST_CASE("RegEx: Longs", "[helpers]") { |
| 821 | 823 | |
| 822 | 824 | CHECK(CLI::detail::split_long("--a", name, value)); |
| 823 | 825 | CHECK(name == "a"); |
| 824 | - CHECK(value == ""); | |
| 826 | + CHECK(value.empty()); | |
| 825 | 827 | |
| 826 | 828 | CHECK(CLI::detail::split_long("--thing", name, value)); |
| 827 | 829 | CHECK(name == "thing"); |
| 828 | - CHECK(value == ""); | |
| 830 | + CHECK(value.empty()); | |
| 829 | 831 | |
| 830 | 832 | CHECK(CLI::detail::split_long("--some=thing", name, value)); |
| 831 | 833 | CHECK(name == "some"); |
| ... | ... | @@ -846,7 +848,7 @@ TEST_CASE("RegEx: SplittingNew", "[helpers]") { |
| 846 | 848 | CHECK_NOTHROW(std::tie(shorts, longs, pname) = CLI::detail::get_names({"--long", "-s", "-q", "--also-long"})); |
| 847 | 849 | CHECK(longs == std::vector<std::string>({"long", "also-long"})); |
| 848 | 850 | CHECK(shorts == std::vector<std::string>({"s", "q"})); |
| 849 | - CHECK(pname == ""); | |
| 851 | + CHECK(pname.empty()); | |
| 850 | 852 | |
| 851 | 853 | std::tie(shorts, longs, pname) = CLI::detail::get_names({"--long", "", "-s", "-q", "", "--also-long"}); |
| 852 | 854 | CHECK(longs == std::vector<std::string>({"long", "also-long"})); |
| ... | ... | @@ -1028,33 +1030,33 @@ TEST_CASE("Types: TypeName", "[helpers]") { |
| 1028 | 1030 | } |
| 1029 | 1031 | |
| 1030 | 1032 | TEST_CASE("Types: OverflowSmall", "[helpers]") { |
| 1031 | - signed char x; | |
| 1033 | + signed char x = 0; | |
| 1032 | 1034 | auto strmax = std::to_string((std::numeric_limits<signed char>::max)() + 1); |
| 1033 | 1035 | CHECK_FALSE(CLI::detail::lexical_cast(strmax, x)); |
| 1034 | 1036 | |
| 1035 | - unsigned char y; | |
| 1037 | + unsigned char y = 0; | |
| 1036 | 1038 | strmax = std::to_string((std::numeric_limits<unsigned char>::max)() + 1); |
| 1037 | 1039 | CHECK_FALSE(CLI::detail::lexical_cast(strmax, y)); |
| 1038 | 1040 | } |
| 1039 | 1041 | |
| 1040 | 1042 | TEST_CASE("Types: LexicalCastInt", "[helpers]") { |
| 1041 | 1043 | std::string signed_input = "-912"; |
| 1042 | - int x_signed; | |
| 1044 | + int x_signed = 0; | |
| 1043 | 1045 | CHECK(CLI::detail::lexical_cast(signed_input, x_signed)); |
| 1044 | 1046 | CHECK(x_signed == -912); |
| 1045 | 1047 | |
| 1046 | 1048 | std::string unsigned_input = "912"; |
| 1047 | - unsigned int x_unsigned; | |
| 1049 | + unsigned int x_unsigned = 0; | |
| 1048 | 1050 | CHECK(CLI::detail::lexical_cast(unsigned_input, x_unsigned)); |
| 1049 | 1051 | CHECK(x_unsigned == (unsigned int)912); |
| 1050 | 1052 | |
| 1051 | 1053 | CHECK_FALSE(CLI::detail::lexical_cast(signed_input, x_unsigned)); |
| 1052 | 1054 | |
| 1053 | - unsigned char y; | |
| 1055 | + unsigned char y = 0; | |
| 1054 | 1056 | std::string overflow_input = std::to_string((std::numeric_limits<uint64_t>::max)()) + "0"; |
| 1055 | 1057 | CHECK_FALSE(CLI::detail::lexical_cast(overflow_input, y)); |
| 1056 | 1058 | |
| 1057 | - char y_signed; | |
| 1059 | + char y_signed = 0; | |
| 1058 | 1060 | CHECK_FALSE(CLI::detail::lexical_cast(overflow_input, y_signed)); |
| 1059 | 1061 | |
| 1060 | 1062 | std::string bad_input = "hello"; |
| ... | ... | @@ -1071,7 +1073,7 @@ TEST_CASE("Types: LexicalCastInt", "[helpers]") { |
| 1071 | 1073 | |
| 1072 | 1074 | TEST_CASE("Types: LexicalCastDouble", "[helpers]") { |
| 1073 | 1075 | std::string input = "9.12"; |
| 1074 | - long double x; | |
| 1076 | + long double x = NAN; | |
| 1075 | 1077 | CHECK(CLI::detail::lexical_cast(input, x)); |
| 1076 | 1078 | CHECK((float)x == Approx((float)9.12)); |
| 1077 | 1079 | |
| ... | ... | @@ -1091,7 +1093,7 @@ TEST_CASE("Types: LexicalCastDouble", "[helpers]") { |
| 1091 | 1093 | |
| 1092 | 1094 | TEST_CASE("Types: LexicalCastBool", "[helpers]") { |
| 1093 | 1095 | std::string input = "false"; |
| 1094 | - bool x; | |
| 1096 | + bool x = false; | |
| 1095 | 1097 | CHECK(CLI::detail::lexical_cast(input, x)); |
| 1096 | 1098 | CHECK_FALSE(x); |
| 1097 | 1099 | |
| ... | ... | @@ -1131,7 +1133,7 @@ TEST_CASE("Types: LexicalCastParsable", "[helpers]") { |
| 1131 | 1133 | TEST_CASE("Types: LexicalCastEnum", "[helpers]") { |
| 1132 | 1134 | enum t1 : signed char { v1 = 5, v3 = 7, v5 = -9 }; |
| 1133 | 1135 | |
| 1134 | - t1 output; | |
| 1136 | + t1 output = v1; | |
| 1135 | 1137 | CHECK(CLI::detail::lexical_cast("-9", output)); |
| 1136 | 1138 | CHECK(v5 == output); |
| 1137 | 1139 | ... | ... |
tests/NewParseTest.cpp
| ... | ... | @@ -8,6 +8,7 @@ |
| 8 | 8 | |
| 9 | 9 | #include <complex> |
| 10 | 10 | #include <cstdint> |
| 11 | +#include <utility> | |
| 11 | 12 | |
| 12 | 13 | using Catch::Matchers::Contains; |
| 13 | 14 | |
| ... | ... | @@ -158,7 +159,7 @@ TEST_CASE_METHOD(TApp, "ComplexSingleImagOption", "[newparse]") { |
| 158 | 159 | class spair { |
| 159 | 160 | public: |
| 160 | 161 | spair() = default; |
| 161 | - spair(const std::string &s1, const std::string &s2) : first(s1), second(s2) {} | |
| 162 | + spair(std::string s1, std::string s2) : first(std::move(s1)), second(std::move(s2)) {} | |
| 162 | 163 | std::string first{}; |
| 163 | 164 | std::string second{}; |
| 164 | 165 | }; |
| ... | ... | @@ -205,15 +206,16 @@ TEST_CASE_METHOD(TApp, "custom_string_converterFail", "[newparse]") { |
| 205 | 206 | template <class X> class objWrapper { |
| 206 | 207 | public: |
| 207 | 208 | objWrapper() = default; |
| 208 | - explicit objWrapper(X obj) : val_{obj} {}; | |
| 209 | + explicit objWrapper(X obj) : val_{std::move(obj)} {}; | |
| 209 | 210 | objWrapper(const objWrapper &ow) = default; |
| 210 | 211 | template <class TT> objWrapper(const TT &obj) = delete; |
| 211 | 212 | objWrapper &operator=(const objWrapper &) = default; |
| 212 | - objWrapper &operator=(objWrapper &&) = default; | |
| 213 | + // noexcept not allowed below by GCC 4.8 | |
| 214 | + objWrapper &operator=(objWrapper &&) = default; // NOLINT(performance-noexcept-move-constructor) | |
| 213 | 215 | // delete all other assignment operators |
| 214 | 216 | template <typename TT> void operator=(TT &&obj) = delete; |
| 215 | 217 | |
| 216 | - const X &value() const { return val_; } | |
| 218 | + CLI11_NODISCARD const X &value() const { return val_; } | |
| 217 | 219 | |
| 218 | 220 | private: |
| 219 | 221 | X val_{}; |
| ... | ... | @@ -312,8 +314,8 @@ class dobjWrapper { |
| 312 | 314 | explicit dobjWrapper(double obj) : dval_{obj} {}; |
| 313 | 315 | explicit dobjWrapper(int obj) : ival_{obj} {}; |
| 314 | 316 | |
| 315 | - double dvalue() const { return dval_; } | |
| 316 | - int ivalue() const { return ival_; } | |
| 317 | + CLI11_NODISCARD double dvalue() const { return dval_; } | |
| 318 | + CLI11_NODISCARD int ivalue() const { return ival_; } | |
| 317 | 319 | |
| 318 | 320 | private: |
| 319 | 321 | double dval_{0.0}; |
| ... | ... | @@ -357,7 +359,7 @@ template <class X> class AobjWrapper { |
| 357 | 359 | // delete all other assignment operators |
| 358 | 360 | template <typename TT> void operator=(TT &&obj) = delete; |
| 359 | 361 | |
| 360 | - const X &value() const { return val_; } | |
| 362 | + CLI11_NODISCARD const X &value() const { return val_; } | |
| 361 | 363 | |
| 362 | 364 | private: |
| 363 | 365 | X val_{}; |
| ... | ... | @@ -389,13 +391,14 @@ TEST_CASE_METHOD(TApp, "uint16Wrapper", "[newparse]") { |
| 389 | 391 | |
| 390 | 392 | template <class T> class SimpleWrapper { |
| 391 | 393 | public: |
| 392 | - SimpleWrapper() : val_{} {}; | |
| 393 | - explicit SimpleWrapper(const T &initial) : val_{initial} {}; | |
| 394 | + SimpleWrapper() = default; | |
| 395 | + | |
| 396 | + explicit SimpleWrapper(T initial) : val_{std::move(initial)} {}; | |
| 394 | 397 | T &getRef() { return val_; } |
| 395 | 398 | using value_type = T; |
| 396 | 399 | |
| 397 | 400 | private: |
| 398 | - T val_; | |
| 401 | + T val_{}; | |
| 399 | 402 | }; |
| 400 | 403 | |
| 401 | 404 | TEST_CASE_METHOD(TApp, "wrapperInt", "[newparse]") { |
| ... | ... | @@ -434,13 +437,13 @@ TEST_CASE_METHOD(TApp, "wrapperwrapperString", "[newparse]") { |
| 434 | 437 | |
| 435 | 438 | run(); |
| 436 | 439 | auto v1 = wrap.getRef().getRef(); |
| 437 | - auto v2 = "arg"; | |
| 440 | + const auto *v2 = "arg"; | |
| 438 | 441 | CHECK(v2 == v1); |
| 439 | 442 | } |
| 440 | 443 | |
| 441 | 444 | TEST_CASE_METHOD(TApp, "wrapperwrapperVector", "[newparse]") { |
| 442 | 445 | SimpleWrapper<SimpleWrapper<std::vector<int>>> wrap; |
| 443 | - auto opt = app.add_option("--val", wrap); | |
| 446 | + auto *opt = app.add_option("--val", wrap); | |
| 444 | 447 | args = {"--val", "1", "2", "3", "4"}; |
| 445 | 448 | |
| 446 | 449 | run(); | ... | ... |
tests/OptionGroupTest.cpp
| ... | ... | @@ -11,8 +11,8 @@ using Catch::Matchers::Contains; |
| 11 | 11 | using vs_t = std::vector<std::string>; |
| 12 | 12 | |
| 13 | 13 | TEST_CASE_METHOD(TApp, "BasicOptionGroup", "[optiongroup]") { |
| 14 | - auto ogroup = app.add_option_group("clusters"); | |
| 15 | - int res; | |
| 14 | + auto *ogroup = app.add_option_group("clusters"); | |
| 15 | + int res = 0; | |
| 16 | 16 | ogroup->add_option("--test1", res); |
| 17 | 17 | ogroup->add_option("--test2", res); |
| 18 | 18 | ogroup->add_option("--test3", res); |
| ... | ... | @@ -34,7 +34,7 @@ TEST_CASE_METHOD(TApp, "OptionGroupInvalidNames", "[optiongroup]") { |
| 34 | 34 | } |
| 35 | 35 | |
| 36 | 36 | TEST_CASE_METHOD(TApp, "BasicOptionGroupExact", "[optiongroup]") { |
| 37 | - auto ogroup = app.add_option_group("clusters"); | |
| 37 | + auto *ogroup = app.add_option_group("clusters"); | |
| 38 | 38 | int res{0}; |
| 39 | 39 | ogroup->add_option("--test1", res); |
| 40 | 40 | ogroup->add_option("--test2", res); |
| ... | ... | @@ -58,7 +58,7 @@ TEST_CASE_METHOD(TApp, "BasicOptionGroupExact", "[optiongroup]") { |
| 58 | 58 | } |
| 59 | 59 | |
| 60 | 60 | TEST_CASE_METHOD(TApp, "BasicOptionGroupExactTooMany", "[optiongroup]") { |
| 61 | - auto ogroup = app.add_option_group("clusters"); | |
| 61 | + auto *ogroup = app.add_option_group("clusters"); | |
| 62 | 62 | int res{0}; |
| 63 | 63 | ogroup->add_option("--test1", res); |
| 64 | 64 | ogroup->add_option("--test2", res); |
| ... | ... | @@ -71,7 +71,7 @@ TEST_CASE_METHOD(TApp, "BasicOptionGroupExactTooMany", "[optiongroup]") { |
| 71 | 71 | } |
| 72 | 72 | |
| 73 | 73 | TEST_CASE_METHOD(TApp, "BasicOptionGroupMinMax", "[optiongroup]") { |
| 74 | - auto ogroup = app.add_option_group("clusters"); | |
| 74 | + auto *ogroup = app.add_option_group("clusters"); | |
| 75 | 75 | int res{0}; |
| 76 | 76 | ogroup->add_option("--test1", res); |
| 77 | 77 | ogroup->add_option("--test2", res); |
| ... | ... | @@ -95,7 +95,7 @@ TEST_CASE_METHOD(TApp, "BasicOptionGroupMinMax", "[optiongroup]") { |
| 95 | 95 | } |
| 96 | 96 | |
| 97 | 97 | TEST_CASE_METHOD(TApp, "BasicOptionGroupMinMaxDifferent", "[optiongroup]") { |
| 98 | - auto ogroup = app.add_option_group("clusters"); | |
| 98 | + auto *ogroup = app.add_option_group("clusters"); | |
| 99 | 99 | int res{0}; |
| 100 | 100 | ogroup->add_option("--test1", res); |
| 101 | 101 | ogroup->add_option("--test2", res); |
| ... | ... | @@ -123,7 +123,7 @@ TEST_CASE_METHOD(TApp, "BasicOptionGroupMinMaxDifferent", "[optiongroup]") { |
| 123 | 123 | } |
| 124 | 124 | |
| 125 | 125 | TEST_CASE_METHOD(TApp, "BasicOptionGroupMinMaxDifferentReversed", "[optiongroup]") { |
| 126 | - auto ogroup = app.add_option_group("clusters"); | |
| 126 | + auto *ogroup = app.add_option_group("clusters"); | |
| 127 | 127 | int res{0}; |
| 128 | 128 | ogroup->add_option("--test1", res); |
| 129 | 129 | ogroup->add_option("--test2", res); |
| ... | ... | @@ -155,12 +155,12 @@ TEST_CASE_METHOD(TApp, "BasicOptionGroupMinMaxDifferentReversed", "[optiongroup] |
| 155 | 155 | } |
| 156 | 156 | |
| 157 | 157 | TEST_CASE_METHOD(TApp, "BasicOptionGroupMax", "[optiongroup]") { |
| 158 | - auto ogroup = app.add_option_group("clusters"); | |
| 158 | + auto *ogroup = app.add_option_group("clusters"); | |
| 159 | 159 | int res{0}; |
| 160 | 160 | ogroup->add_option("--test1", res); |
| 161 | 161 | ogroup->add_option("--test2", res); |
| 162 | 162 | ogroup->add_option("--test3", res); |
| 163 | - int val2; | |
| 163 | + int val2 = 0; | |
| 164 | 164 | app.add_option("--option", val2); |
| 165 | 165 | ogroup->require_option(-2); |
| 166 | 166 | args = {"--test1", "5"}; |
| ... | ... | @@ -179,7 +179,7 @@ TEST_CASE_METHOD(TApp, "BasicOptionGroupMax", "[optiongroup]") { |
| 179 | 179 | } |
| 180 | 180 | |
| 181 | 181 | TEST_CASE_METHOD(TApp, "BasicOptionGroupMax1", "[optiongroup]") { |
| 182 | - auto ogroup = app.add_option_group("clusters"); | |
| 182 | + auto *ogroup = app.add_option_group("clusters"); | |
| 183 | 183 | int res{0}; |
| 184 | 184 | ogroup->add_option("--test1", res); |
| 185 | 185 | ogroup->add_option("--test2", res); |
| ... | ... | @@ -203,7 +203,7 @@ TEST_CASE_METHOD(TApp, "BasicOptionGroupMax1", "[optiongroup]") { |
| 203 | 203 | } |
| 204 | 204 | |
| 205 | 205 | TEST_CASE_METHOD(TApp, "BasicOptionGroupMin", "[optiongroup]") { |
| 206 | - auto ogroup = app.add_option_group("clusters"); | |
| 206 | + auto *ogroup = app.add_option_group("clusters"); | |
| 207 | 207 | int res{0}; |
| 208 | 208 | ogroup->add_option("--test1", res); |
| 209 | 209 | ogroup->add_option("--test2", res); |
| ... | ... | @@ -224,7 +224,7 @@ TEST_CASE_METHOD(TApp, "BasicOptionGroupMin", "[optiongroup]") { |
| 224 | 224 | } |
| 225 | 225 | |
| 226 | 226 | TEST_CASE_METHOD(TApp, "BasicOptionGroupExact2", "[optiongroup]") { |
| 227 | - auto ogroup = app.add_option_group("clusters"); | |
| 227 | + auto *ogroup = app.add_option_group("clusters"); | |
| 228 | 228 | int res{0}; |
| 229 | 229 | ogroup->add_option("--test1", res); |
| 230 | 230 | ogroup->add_option("--test2", res); |
| ... | ... | @@ -248,7 +248,7 @@ TEST_CASE_METHOD(TApp, "BasicOptionGroupExact2", "[optiongroup]") { |
| 248 | 248 | } |
| 249 | 249 | |
| 250 | 250 | TEST_CASE_METHOD(TApp, "BasicOptionGroupMin2", "[optiongroup]") { |
| 251 | - auto ogroup = app.add_option_group("clusters"); | |
| 251 | + auto *ogroup = app.add_option_group("clusters"); | |
| 252 | 252 | int res{0}; |
| 253 | 253 | ogroup->add_option("--test1", res); |
| 254 | 254 | ogroup->add_option("--test2", res); |
| ... | ... | @@ -271,13 +271,13 @@ TEST_CASE_METHOD(TApp, "BasicOptionGroupMin2", "[optiongroup]") { |
| 271 | 271 | TEST_CASE_METHOD(TApp, "BasicOptionGroupMinMoved", "[optiongroup]") { |
| 272 | 272 | |
| 273 | 273 | int res{0}; |
| 274 | - auto opt1 = app.add_option("--test1", res); | |
| 275 | - auto opt2 = app.add_option("--test2", res); | |
| 276 | - auto opt3 = app.add_option("--test3", res); | |
| 274 | + auto *opt1 = app.add_option("--test1", res); | |
| 275 | + auto *opt2 = app.add_option("--test2", res); | |
| 276 | + auto *opt3 = app.add_option("--test3", res); | |
| 277 | 277 | int val2{0}; |
| 278 | 278 | app.add_option("--option", val2); |
| 279 | 279 | |
| 280 | - auto ogroup = app.add_option_group("clusters"); | |
| 280 | + auto *ogroup = app.add_option_group("clusters"); | |
| 281 | 281 | ogroup->require_option(); |
| 282 | 282 | ogroup->add_option(opt1); |
| 283 | 283 | ogroup->add_option(opt2); |
| ... | ... | @@ -300,13 +300,13 @@ TEST_CASE_METHOD(TApp, "BasicOptionGroupMinMoved", "[optiongroup]") { |
| 300 | 300 | TEST_CASE_METHOD(TApp, "BasicOptionGroupMinMovedAsGroup", "[optiongroup]") { |
| 301 | 301 | |
| 302 | 302 | int res{0}; |
| 303 | - auto opt1 = app.add_option("--test1", res); | |
| 304 | - auto opt2 = app.add_option("--test2", res); | |
| 305 | - auto opt3 = app.add_option("--test3", res); | |
| 303 | + auto *opt1 = app.add_option("--test1", res); | |
| 304 | + auto *opt2 = app.add_option("--test2", res); | |
| 305 | + auto *opt3 = app.add_option("--test3", res); | |
| 306 | 306 | int val2{0}; |
| 307 | 307 | app.add_option("--option", val2); |
| 308 | 308 | |
| 309 | - auto ogroup = app.add_option_group("clusters"); | |
| 309 | + auto *ogroup = app.add_option_group("clusters"); | |
| 310 | 310 | ogroup->require_option(); |
| 311 | 311 | ogroup->add_options(opt1, opt2, opt3); |
| 312 | 312 | |
| ... | ... | @@ -328,17 +328,17 @@ TEST_CASE_METHOD(TApp, "BasicOptionGroupMinMovedAsGroup", "[optiongroup]") { |
| 328 | 328 | TEST_CASE_METHOD(TApp, "BasicOptionGroupAddFailures", "[optiongroup]") { |
| 329 | 329 | |
| 330 | 330 | int res{0}; |
| 331 | - auto opt1 = app.add_option("--test1", res); | |
| 331 | + auto *opt1 = app.add_option("--test1", res); | |
| 332 | 332 | app.set_config("--config"); |
| 333 | 333 | int val2{0}; |
| 334 | 334 | app.add_option("--option", val2); |
| 335 | 335 | |
| 336 | - auto ogroup = app.add_option_group("clusters"); | |
| 336 | + auto *ogroup = app.add_option_group("clusters"); | |
| 337 | 337 | CHECK_THROWS_AS(ogroup->add_options(app.get_config_ptr()), CLI::OptionAlreadyAdded); |
| 338 | 338 | CHECK_THROWS_AS(ogroup->add_options(app.get_help_ptr()), CLI::OptionAlreadyAdded); |
| 339 | 339 | |
| 340 | - auto sub = app.add_subcommand("sub", "subcommand"); | |
| 341 | - auto opt2 = sub->add_option("--option2", val2); | |
| 340 | + auto *sub = app.add_subcommand("sub", "subcommand"); | |
| 341 | + auto *opt2 = sub->add_option("--option2", val2); | |
| 342 | 342 | |
| 343 | 343 | CHECK_THROWS_AS(ogroup->add_option(opt2), CLI::OptionNotFound); |
| 344 | 344 | |
| ... | ... | @@ -346,7 +346,7 @@ TEST_CASE_METHOD(TApp, "BasicOptionGroupAddFailures", "[optiongroup]") { |
| 346 | 346 | |
| 347 | 347 | ogroup->add_option(opt1); |
| 348 | 348 | |
| 349 | - auto opt3 = app.add_option("--test1", res); | |
| 349 | + auto *opt3 = app.add_option("--test1", res); | |
| 350 | 350 | |
| 351 | 351 | CHECK_THROWS_AS(ogroup->add_option(opt3), CLI::OptionAlreadyAdded); |
| 352 | 352 | } |
| ... | ... | @@ -354,14 +354,14 @@ TEST_CASE_METHOD(TApp, "BasicOptionGroupAddFailures", "[optiongroup]") { |
| 354 | 354 | TEST_CASE_METHOD(TApp, "BasicOptionGroupScrewedUpMove", "[optiongroup]") { |
| 355 | 355 | |
| 356 | 356 | int res{0}; |
| 357 | - auto opt1 = app.add_option("--test1", res); | |
| 358 | - auto opt2 = app.add_option("--test2", res); | |
| 357 | + auto *opt1 = app.add_option("--test1", res); | |
| 358 | + auto *opt2 = app.add_option("--test2", res); | |
| 359 | 359 | int val2{0}; |
| 360 | 360 | app.add_option("--option", val2); |
| 361 | 361 | |
| 362 | - auto ogroup = app.add_option_group("clusters"); | |
| 362 | + auto *ogroup = app.add_option_group("clusters"); | |
| 363 | 363 | ogroup->require_option(); |
| 364 | - auto ogroup2 = ogroup->add_option_group("clusters2"); | |
| 364 | + auto *ogroup2 = ogroup->add_option_group("clusters2"); | |
| 365 | 365 | CHECK_THROWS_AS(ogroup2->add_options(opt1, opt2), CLI::OptionNotFound); |
| 366 | 366 | |
| 367 | 367 | CLI::Option_group EmptyGroup("description", "new group", nullptr); |
| ... | ... | @@ -371,7 +371,7 @@ TEST_CASE_METHOD(TApp, "BasicOptionGroupScrewedUpMove", "[optiongroup]") { |
| 371 | 371 | } |
| 372 | 372 | |
| 373 | 373 | TEST_CASE_METHOD(TApp, "InvalidOptions", "[optiongroup]") { |
| 374 | - auto ogroup = app.add_option_group("clusters"); | |
| 374 | + auto *ogroup = app.add_option_group("clusters"); | |
| 375 | 375 | CLI::Option *opt = nullptr; |
| 376 | 376 | CHECK_THROWS_AS(ogroup->excludes(opt), CLI::OptionNotFound); |
| 377 | 377 | CLI::App *app_p = nullptr; |
| ... | ... | @@ -382,7 +382,7 @@ TEST_CASE_METHOD(TApp, "InvalidOptions", "[optiongroup]") { |
| 382 | 382 | |
| 383 | 383 | TEST_CASE_METHOD(TApp, "OptionGroupInheritedOptionDefaults", "[optiongroup]") { |
| 384 | 384 | app.option_defaults()->ignore_case(); |
| 385 | - auto ogroup = app.add_option_group("clusters"); | |
| 385 | + auto *ogroup = app.add_option_group("clusters"); | |
| 386 | 386 | int res{0}; |
| 387 | 387 | ogroup->add_option("--test1", res); |
| 388 | 388 | |
| ... | ... | @@ -421,7 +421,7 @@ struct ManyGroups : public TApp { |
| 421 | 421 | g3->add_option("--val3", val3); |
| 422 | 422 | } |
| 423 | 423 | |
| 424 | - void remove_required() { | |
| 424 | + void remove_required() { // NOLINT(readability-make-member-function-const) | |
| 425 | 425 | g1->get_option("--name1")->required(false); |
| 426 | 426 | g2->get_option("--name2")->required(false); |
| 427 | 427 | g3->get_option("--name3")->required(false); |
| ... | ... | @@ -486,8 +486,8 @@ TEST_CASE_METHOD(ManyGroups, "NeedsGroup", "[optiongroup]") { |
| 486 | 486 | // test adding an option group with existing subcommands to an app |
| 487 | 487 | TEST_CASE_METHOD(TApp, "ExistingSubcommandMatch", "[optiongroup]") { |
| 488 | 488 | auto sshared = std::make_shared<CLI::Option_group>("documenting the subcommand", "sub1g", nullptr); |
| 489 | - auto s1 = sshared->add_subcommand("sub1"); | |
| 490 | - auto o1 = sshared->add_option_group("opt1"); | |
| 489 | + auto *s1 = sshared->add_subcommand("sub1"); | |
| 490 | + auto *o1 = sshared->add_option_group("opt1"); | |
| 491 | 491 | o1->add_subcommand("sub3")->alias("sub4"); |
| 492 | 492 | |
| 493 | 493 | app.add_subcommand("sub1"); |
| ... | ... | @@ -597,9 +597,9 @@ TEST_CASE_METHOD(ManyGroups, "DisableFirst", "[optiongroup]") { |
| 597 | 597 | TEST_CASE_METHOD(ManyGroups, "SameSubcommand", "[optiongroup]") { |
| 598 | 598 | // only 1 group can be used if remove_required not used |
| 599 | 599 | remove_required(); |
| 600 | - auto sub1 = g1->add_subcommand("sub1")->disabled(); | |
| 601 | - auto sub2 = g2->add_subcommand("sub1")->disabled(); | |
| 602 | - auto sub3 = g3->add_subcommand("sub1"); | |
| 600 | + auto *sub1 = g1->add_subcommand("sub1")->disabled(); | |
| 601 | + auto *sub2 = g2->add_subcommand("sub1")->disabled(); | |
| 602 | + auto *sub3 = g3->add_subcommand("sub1"); | |
| 603 | 603 | // so when the subcommands are disabled they can have the same name |
| 604 | 604 | sub1->disabled(false); |
| 605 | 605 | sub2->disabled(false); |
| ... | ... | @@ -679,7 +679,7 @@ TEST_CASE_METHOD(ManyGroups, "Inheritance", "[optiongroup]") { |
| 679 | 679 | remove_required(); |
| 680 | 680 | g1->ignore_case(); |
| 681 | 681 | g1->ignore_underscore(); |
| 682 | - auto t2 = g1->add_subcommand("t2"); | |
| 682 | + auto *t2 = g1->add_subcommand("t2"); | |
| 683 | 683 | args = {"T2", "t_2"}; |
| 684 | 684 | CHECK(t2->get_ignore_underscore()); |
| 685 | 685 | CHECK(t2->get_ignore_case()); |
| ... | ... | @@ -689,7 +689,7 @@ TEST_CASE_METHOD(ManyGroups, "Inheritance", "[optiongroup]") { |
| 689 | 689 | |
| 690 | 690 | TEST_CASE_METHOD(ManyGroups, "Moving", "[optiongroup]") { |
| 691 | 691 | remove_required(); |
| 692 | - auto mg = app.add_option_group("maing"); | |
| 692 | + auto *mg = app.add_option_group("maing"); | |
| 693 | 693 | mg->add_subcommand(g1); |
| 694 | 694 | mg->add_subcommand(g2); |
| 695 | 695 | |
| ... | ... | @@ -767,11 +767,11 @@ TEST_CASE_METHOD(ManyGroupsPreTrigger, "PreTriggerTestsPositionals", "[optiongro |
| 767 | 767 | |
| 768 | 768 | TEST_CASE_METHOD(ManyGroupsPreTrigger, "PreTriggerTestsSubcommand", "[optiongroup]") { |
| 769 | 769 | |
| 770 | - auto sub1 = g1->add_subcommand("sub1")->fallthrough(); | |
| 770 | + auto *sub1 = g1->add_subcommand("sub1")->fallthrough(); | |
| 771 | 771 | g2->add_subcommand("sub2")->fallthrough(); |
| 772 | 772 | g3->add_subcommand("sub3")->fallthrough(); |
| 773 | 773 | |
| 774 | - std::size_t subtrigger; | |
| 774 | + std::size_t subtrigger = 0; | |
| 775 | 775 | sub1->preparse_callback([&subtrigger](std::size_t count) { subtrigger = count; }); |
| 776 | 776 | args = {"sub1"}; |
| 777 | 777 | run(); | ... | ... |
tests/OptionTypeTest.cpp
| ... | ... | @@ -5,7 +5,9 @@ |
| 5 | 5 | // SPDX-License-Identifier: BSD-3-Clause |
| 6 | 6 | |
| 7 | 7 | #include "app_helper.hpp" |
| 8 | + | |
| 8 | 9 | #include <atomic> |
| 10 | +#include <cmath> | |
| 9 | 11 | #include <complex> |
| 10 | 12 | #include <cstdint> |
| 11 | 13 | #include <cstdlib> |
| ... | ... | @@ -17,8 +19,11 @@ |
| 17 | 19 | #include <set> |
| 18 | 20 | #include <unordered_map> |
| 19 | 21 | #include <unordered_set> |
| 22 | +#include <utility> | |
| 20 | 23 | #include <vector> |
| 21 | 24 | |
| 25 | +using Catch::literals::operator"" _a; | |
| 26 | + | |
| 22 | 27 | TEST_CASE_METHOD(TApp, "OneStringAgain", "[optiontype]") { |
| 23 | 28 | std::string str; |
| 24 | 29 | app.add_option("-s,--string", str); |
| ... | ... | @@ -44,13 +49,13 @@ TEST_CASE_METHOD(TApp, "doubleFunction", "[optiontype]") { |
| 44 | 49 | app.add_option_function<double>("--val", [&res](double val) { res = std::abs(val + 54); }); |
| 45 | 50 | args = {"--val", "-354.356"}; |
| 46 | 51 | run(); |
| 47 | - CHECK(300.356 == res); | |
| 52 | + CHECK(300.356_a == res); | |
| 48 | 53 | // get the original value as entered as an integer |
| 49 | - CHECK(-354.356f == app["--val"]->as<float>()); | |
| 54 | + CHECK(-354.356_a == app["--val"]->as<float>()); | |
| 50 | 55 | } |
| 51 | 56 | |
| 52 | 57 | TEST_CASE_METHOD(TApp, "doubleFunctionFail", "[optiontype]") { |
| 53 | - double res; | |
| 58 | + double res = NAN; | |
| 54 | 59 | app.add_option_function<double>("--val", [&res](double val) { res = std::abs(val + 54); }); |
| 55 | 60 | args = {"--val", "not_double"}; |
| 56 | 61 | CHECK_THROWS_AS(run(), CLI::ConversionError); |
| ... | ... | @@ -65,8 +70,8 @@ TEST_CASE_METHOD(TApp, "doubleVectorFunction", "[optiontype]") { |
| 65 | 70 | args = {"--val", "5", "--val", "6", "--val", "7"}; |
| 66 | 71 | run(); |
| 67 | 72 | CHECK(3u == res.size()); |
| 68 | - CHECK(10.0 == res[0]); | |
| 69 | - CHECK(12.0 == res[2]); | |
| 73 | + CHECK(10.0_a == res[0]); | |
| 74 | + CHECK(12.0_a == res[2]); | |
| 70 | 75 | } |
| 71 | 76 | |
| 72 | 77 | TEST_CASE_METHOD(TApp, "doubleVectorFunctionFail", "[optiontype]") { |
| ... | ... | @@ -86,7 +91,7 @@ TEST_CASE_METHOD(TApp, "doubleVectorFunctionFail", "[optiontype]") { |
| 86 | 91 | |
| 87 | 92 | TEST_CASE_METHOD(TApp, "doubleVectorFunctionRunCallbackOnDefault", "[optiontype]") { |
| 88 | 93 | std::vector<double> res; |
| 89 | - auto opt = app.add_option_function<std::vector<double>>("--val", [&res](const std::vector<double> &val) { | |
| 94 | + auto *opt = app.add_option_function<std::vector<double>>("--val", [&res](const std::vector<double> &val) { | |
| 90 | 95 | res = val; |
| 91 | 96 | std::transform(res.begin(), res.end(), res.begin(), [](double v) { return v + 5.0; }); |
| 92 | 97 | }); |
| ... | ... | @@ -195,7 +200,7 @@ TEST_CASE_METHOD(TApp, "BoolOption", "[optiontype]") { |
| 195 | 200 | |
| 196 | 201 | TEST_CASE_METHOD(TApp, "atomic_int_option", "[optiontype]") { |
| 197 | 202 | std::atomic<int> i{0}; |
| 198 | - auto aopt = app.add_option("-i,--int", i); | |
| 203 | + auto *aopt = app.add_option("-i,--int", i); | |
| 199 | 204 | args = {"-i4"}; |
| 200 | 205 | run(); |
| 201 | 206 | CHECK(app.count("--int") == 1u); |
| ... | ... | @@ -240,7 +245,7 @@ TEST_CASE_METHOD(TApp, "CharOption", "[optiontype]") { |
| 240 | 245 | |
| 241 | 246 | TEST_CASE_METHOD(TApp, "vectorDefaults", "[optiontype]") { |
| 242 | 247 | std::vector<int> vals{4, 5}; |
| 243 | - auto opt = app.add_option("--long", vals)->capture_default_str(); | |
| 248 | + auto *opt = app.add_option("--long", vals)->capture_default_str(); | |
| 244 | 249 | |
| 245 | 250 | args = {"--long", "[1,2,3]"}; |
| 246 | 251 | |
| ... | ... | @@ -286,7 +291,7 @@ TEST_CASE_METHOD(TApp, "CallbackBoolFlags", "[optiontype]") { |
| 286 | 291 | |
| 287 | 292 | auto func = [&value]() { value = true; }; |
| 288 | 293 | |
| 289 | - auto cback = app.add_flag_callback("--val", func); | |
| 294 | + auto *cback = app.add_flag_callback("--val", func); | |
| 290 | 295 | args = {"--val"}; |
| 291 | 296 | run(); |
| 292 | 297 | CHECK(value); |
| ... | ... | @@ -339,7 +344,7 @@ TEST_CASE_METHOD(TApp, "pair_check_take_first", "[optiontype]") { |
| 339 | 344 | CHECK(CLI::ExistingFile(myfile).empty()); |
| 340 | 345 | std::pair<std::string, int> findex; |
| 341 | 346 | |
| 342 | - auto opt = app.add_option("--file", findex)->check(CLI::ExistingFile)->check(CLI::PositiveNumber); | |
| 347 | + auto *opt = app.add_option("--file", findex)->check(CLI::ExistingFile)->check(CLI::PositiveNumber); | |
| 343 | 348 | CHECK_THROWS_AS(opt->get_validator(3), CLI::OptionNotFound); |
| 344 | 349 | opt->get_validator(0)->application_index(0); |
| 345 | 350 | opt->get_validator(1)->application_index(1); |
| ... | ... | @@ -422,7 +427,7 @@ TEST_CASE_METHOD(TApp, "VectorUnlimString", "[optiontype]") { |
| 422 | 427 | // From https://github.com/CLIUtils/CLI11/issues/420 |
| 423 | 428 | TEST_CASE_METHOD(TApp, "stringLikeTests", "[optiontype]") { |
| 424 | 429 | struct nType { |
| 425 | - explicit nType(const std::string &a_value) : m_value{a_value} {} | |
| 430 | + explicit nType(std::string a_value) : m_value{std::move(a_value)} {} | |
| 426 | 431 | |
| 427 | 432 | explicit operator std::string() const { return std::string{"op str"}; } |
| 428 | 433 | |
| ... | ... | @@ -492,7 +497,7 @@ TEST_CASE_METHOD(TApp, "CustomDoubleOption", "[optiontype]") { |
| 492 | 497 | |
| 493 | 498 | std::pair<int, double> custom_opt; |
| 494 | 499 | |
| 495 | - auto opt = app.add_option("posit", [&custom_opt](CLI::results_t vals) { | |
| 500 | + auto *opt = app.add_option("posit", [&custom_opt](CLI::results_t vals) { | |
| 496 | 501 | custom_opt = {stol(vals.at(0)), stod(vals.at(1))}; |
| 497 | 502 | return true; |
| 498 | 503 | }); |
| ... | ... | @@ -544,7 +549,7 @@ TEST_CASE_METHOD(TApp, "vectorPair", "[optiontype]") { |
| 544 | 549 | |
| 545 | 550 | std::vector<std::pair<int, std::string>> custom_opt; |
| 546 | 551 | |
| 547 | - auto opt = app.add_option("--dict", custom_opt); | |
| 552 | + auto *opt = app.add_option("--dict", custom_opt); | |
| 548 | 553 | |
| 549 | 554 | args = {"--dict", "1", "str1", "--dict", "3", "str3"}; |
| 550 | 555 | |
| ... | ... | @@ -578,7 +583,7 @@ TEST_CASE_METHOD(TApp, "vectorPairFail2", "[optiontype]") { |
| 578 | 583 | |
| 579 | 584 | std::vector<std::pair<int, int>> custom_opt; |
| 580 | 585 | |
| 581 | - auto opt = app.add_option("--pairs", custom_opt); | |
| 586 | + auto *opt = app.add_option("--pairs", custom_opt); | |
| 582 | 587 | |
| 583 | 588 | args = {"--pairs", "1", "2", "3", "4"}; |
| 584 | 589 | |
| ... | ... | @@ -599,7 +604,7 @@ TEST_CASE_METHOD(TApp, "vectorPairTypeRange", "[optiontype]") { |
| 599 | 604 | |
| 600 | 605 | std::vector<std::pair<int, std::string>> custom_opt; |
| 601 | 606 | |
| 602 | - auto opt = app.add_option("--dict", custom_opt); | |
| 607 | + auto *opt = app.add_option("--dict", custom_opt); | |
| 603 | 608 | |
| 604 | 609 | opt->type_size(2, 1); // just test switched arguments |
| 605 | 610 | CHECK(1 == opt->get_type_size_min()); |
| ... | ... | @@ -635,7 +640,7 @@ TEST_CASE_METHOD(TApp, "vectorTuple", "[optiontype]") { |
| 635 | 640 | |
| 636 | 641 | std::vector<std::tuple<int, std::string, double>> custom_opt; |
| 637 | 642 | |
| 638 | - auto opt = app.add_option("--dict", custom_opt); | |
| 643 | + auto *opt = app.add_option("--dict", custom_opt); | |
| 639 | 644 | |
| 640 | 645 | args = {"--dict", "1", "str1", "4.3", "--dict", "3", "str3", "2.7"}; |
| 641 | 646 | |
| ... | ... | @@ -665,7 +670,7 @@ TEST_CASE_METHOD(TApp, "vectorVector", "[optiontype]") { |
| 665 | 670 | |
| 666 | 671 | std::vector<std::vector<int>> custom_opt; |
| 667 | 672 | |
| 668 | - auto opt = app.add_option("--dict", custom_opt); | |
| 673 | + auto *opt = app.add_option("--dict", custom_opt); | |
| 669 | 674 | |
| 670 | 675 | args = {"--dict", "1", "2", "4", "--dict", "3", "1"}; |
| 671 | 676 | |
| ... | ... | @@ -701,7 +706,7 @@ TEST_CASE_METHOD(TApp, "vectorVectorFixedSize", "[optiontype]") { |
| 701 | 706 | |
| 702 | 707 | std::vector<std::vector<int>> custom_opt; |
| 703 | 708 | |
| 704 | - auto opt = app.add_option("--dict", custom_opt)->type_size(4); | |
| 709 | + auto *opt = app.add_option("--dict", custom_opt)->type_size(4); | |
| 705 | 710 | |
| 706 | 711 | args = {"--dict", "1", "2", "4", "3", "--dict", "3", "1", "2", "8"}; |
| 707 | 712 | |
| ... | ... | @@ -905,7 +910,7 @@ TEST_CASE_METHOD(TApp, "unknownContainerWrapper", "[optiontype]") { |
| 905 | 910 | class vopt { |
| 906 | 911 | public: |
| 907 | 912 | vopt() = default; |
| 908 | - explicit vopt(const std::vector<double> &vdub) : val_{vdub} {}; | |
| 913 | + explicit vopt(std::vector<double> vdub) : val_{std::move(vdub)} {}; | |
| 909 | 914 | std::vector<double> val_{}; |
| 910 | 915 | }; |
| 911 | 916 | ... | ... |
tests/SetTest.cpp
| ... | ... | @@ -6,6 +6,7 @@ |
| 6 | 6 | |
| 7 | 7 | #include "app_helper.hpp" |
| 8 | 8 | #include <map> |
| 9 | +#include <memory> | |
| 9 | 10 | |
| 10 | 11 | static_assert(CLI::is_shared_ptr<std::shared_ptr<int>>::value == true, "is_shared_ptr should work on shared pointers"); |
| 11 | 12 | static_assert(CLI::is_shared_ptr<int *>::value == false, "is_shared_ptr should work on pointers"); |
| ... | ... | @@ -34,7 +35,7 @@ static_assert(CLI::detail::pair_adaptor<std::vector<std::pair<int, int>>>::value |
| 34 | 35 | TEST_CASE_METHOD(TApp, "SimpleMaps", "[set]") { |
| 35 | 36 | int value{0}; |
| 36 | 37 | std::map<std::string, int> map = {{"one", 1}, {"two", 2}}; |
| 37 | - auto opt = app.add_option("-s,--set", value)->transform(CLI::Transformer(map)); | |
| 38 | + auto *opt = app.add_option("-s,--set", value)->transform(CLI::Transformer(map)); | |
| 38 | 39 | args = {"-s", "one"}; |
| 39 | 40 | run(); |
| 40 | 41 | CHECK(app.count("-s") == 1u); |
| ... | ... | @@ -78,9 +79,9 @@ TEST_CASE_METHOD(TApp, "StringStringMapNoModify", "[set]") { |
| 78 | 79 | enum SimpleEnum { SE_one = 1, SE_two = 2 }; |
| 79 | 80 | |
| 80 | 81 | TEST_CASE_METHOD(TApp, "EnumMap", "[set]") { |
| 81 | - SimpleEnum value; | |
| 82 | + SimpleEnum value; // NOLINT(cppcoreguidelines-init-variables) | |
| 82 | 83 | std::map<std::string, SimpleEnum> map = {{"one", SE_one}, {"two", SE_two}}; |
| 83 | - auto opt = app.add_option("-s,--set", value)->transform(CLI::Transformer(map)); | |
| 84 | + auto *opt = app.add_option("-s,--set", value)->transform(CLI::Transformer(map)); | |
| 84 | 85 | args = {"-s", "one"}; |
| 85 | 86 | run(); |
| 86 | 87 | CHECK(app.count("-s") == 1u); |
| ... | ... | @@ -92,9 +93,9 @@ TEST_CASE_METHOD(TApp, "EnumMap", "[set]") { |
| 92 | 93 | enum class SimpleEnumC { one = 1, two = 2 }; |
| 93 | 94 | |
| 94 | 95 | TEST_CASE_METHOD(TApp, "EnumCMap", "[set]") { |
| 95 | - SimpleEnumC value; | |
| 96 | + SimpleEnumC value; // NOLINT(cppcoreguidelines-init-variables) | |
| 96 | 97 | std::map<std::string, SimpleEnumC> map = {{"one", SimpleEnumC::one}, {"two", SimpleEnumC::two}}; |
| 97 | - auto opt = app.add_option("-s,--set", value)->transform(CLI::Transformer(map)); | |
| 98 | + auto *opt = app.add_option("-s,--set", value)->transform(CLI::Transformer(map)); | |
| 98 | 99 | args = {"-s", "one"}; |
| 99 | 100 | run(); |
| 100 | 101 | CHECK(app.count("-s") == 1u); |
| ... | ... | @@ -111,7 +112,7 @@ TEST_CASE_METHOD(TApp, "structMap", "[set]") { |
| 111 | 112 | }; |
| 112 | 113 | std::string struct_name; |
| 113 | 114 | std::map<std::string, struct tstruct> map = {{"sone", {4, 32.4, "foo"}}, {"stwo", {5, 99.7, "bar"}}}; |
| 114 | - auto opt = app.add_option("-s,--set", struct_name)->check(CLI::IsMember(map)); | |
| 115 | + auto *opt = app.add_option("-s,--set", struct_name)->check(CLI::IsMember(map)); | |
| 115 | 116 | args = {"-s", "sone"}; |
| 116 | 117 | run(); |
| 117 | 118 | CHECK(app.count("-s") == 1u); |
| ... | ... | @@ -131,8 +132,8 @@ TEST_CASE_METHOD(TApp, "structMapChange", "[set]") { |
| 131 | 132 | }; |
| 132 | 133 | std::string struct_name; |
| 133 | 134 | std::map<std::string, struct tstruct> map = {{"sone", {4, 32.4, "foo"}}, {"stwo", {5, 99.7, "bar"}}}; |
| 134 | - auto opt = app.add_option("-s,--set", struct_name) | |
| 135 | - ->transform(CLI::IsMember(map, CLI::ignore_case, CLI::ignore_underscore, CLI::ignore_space)); | |
| 135 | + auto *opt = app.add_option("-s,--set", struct_name) | |
| 136 | + ->transform(CLI::IsMember(map, CLI::ignore_case, CLI::ignore_underscore, CLI::ignore_space)); | |
| 136 | 137 | args = {"-s", "s one"}; |
| 137 | 138 | run(); |
| 138 | 139 | CHECK(app.count("-s") == 1u); |
| ... | ... | @@ -159,8 +160,8 @@ TEST_CASE_METHOD(TApp, "structMapNoChange", "[set]") { |
| 159 | 160 | }; |
| 160 | 161 | std::string struct_name; |
| 161 | 162 | std::map<std::string, struct tstruct> map = {{"sone", {4, 32.4, "foo"}}, {"stwo", {5, 99.7, "bar"}}}; |
| 162 | - auto opt = app.add_option("-s,--set", struct_name) | |
| 163 | - ->check(CLI::IsMember(map, CLI::ignore_case, CLI::ignore_underscore, CLI::ignore_space)); | |
| 163 | + auto *opt = app.add_option("-s,--set", struct_name) | |
| 164 | + ->check(CLI::IsMember(map, CLI::ignore_case, CLI::ignore_underscore, CLI::ignore_space)); | |
| 164 | 165 | args = {"-s", "SONE"}; |
| 165 | 166 | run(); |
| 166 | 167 | CHECK(app.count("-s") == 1u); |
| ... | ... | @@ -184,9 +185,9 @@ TEST_CASE_METHOD(TApp, "NonCopyableMap", "[set]") { |
| 184 | 185 | |
| 185 | 186 | std::string map_name; |
| 186 | 187 | std::map<std::string, std::unique_ptr<double>> map; |
| 187 | - map["e1"] = std::unique_ptr<double>(new double(5.7)); | |
| 188 | - map["e3"] = std::unique_ptr<double>(new double(23.8)); | |
| 189 | - auto opt = app.add_option("-s,--set", map_name)->check(CLI::IsMember(&map)); | |
| 188 | + map["e1"].reset(new double(5.7)); | |
| 189 | + map["e3"].reset(new double(23.8)); | |
| 190 | + auto *opt = app.add_option("-s,--set", map_name)->check(CLI::IsMember(&map)); | |
| 190 | 191 | args = {"-s", "e1"}; |
| 191 | 192 | run(); |
| 192 | 193 | CHECK(app.count("-s") == 1u); |
| ... | ... | @@ -202,9 +203,9 @@ TEST_CASE_METHOD(TApp, "NonCopyableMapWithFunction", "[set]") { |
| 202 | 203 | |
| 203 | 204 | std::string map_name; |
| 204 | 205 | std::map<std::string, std::unique_ptr<double>> map; |
| 205 | - map["e1"] = std::unique_ptr<double>(new double(5.7)); | |
| 206 | - map["e3"] = std::unique_ptr<double>(new double(23.8)); | |
| 207 | - auto opt = app.add_option("-s,--set", map_name)->transform(CLI::IsMember(&map, CLI::ignore_underscore)); | |
| 206 | + map["e1"].reset(new double(5.7)); | |
| 207 | + map["e3"].reset(new double(23.8)); | |
| 208 | + auto *opt = app.add_option("-s,--set", map_name)->transform(CLI::IsMember(&map, CLI::ignore_underscore)); | |
| 208 | 209 | args = {"-s", "e_1"}; |
| 209 | 210 | run(); |
| 210 | 211 | CHECK(app.count("-s") == 1u); |
| ... | ... | @@ -220,9 +221,9 @@ TEST_CASE_METHOD(TApp, "NonCopyableMapNonStringMap", "[set]") { |
| 220 | 221 | |
| 221 | 222 | std::string map_name; |
| 222 | 223 | std::map<int, std::unique_ptr<double>> map; |
| 223 | - map[4] = std::unique_ptr<double>(new double(5.7)); | |
| 224 | - map[17] = std::unique_ptr<double>(new double(23.8)); | |
| 225 | - auto opt = app.add_option("-s,--set", map_name)->check(CLI::IsMember(&map)); | |
| 224 | + map[4].reset(new double(5.7)); | |
| 225 | + map[17].reset(new double(23.8)); | |
| 226 | + auto *opt = app.add_option("-s,--set", map_name)->check(CLI::IsMember(&map)); | |
| 226 | 227 | args = {"-s", "4"}; |
| 227 | 228 | run(); |
| 228 | 229 | CHECK(app.count("-s") == 1u); |
| ... | ... | @@ -240,7 +241,7 @@ TEST_CASE_METHOD(TApp, "CopyableMapMove", "[set]") { |
| 240 | 241 | std::map<int, double> map; |
| 241 | 242 | map[4] = 5.7; |
| 242 | 243 | map[17] = 23.8; |
| 243 | - auto opt = app.add_option("-s,--set", map_name)->check(CLI::IsMember(std::move(map))); | |
| 244 | + auto *opt = app.add_option("-s,--set", map_name)->check(CLI::IsMember(std::move(map))); | |
| 244 | 245 | args = {"-s", "4"}; |
| 245 | 246 | run(); |
| 246 | 247 | CHECK(app.count("-s") == 1u); |
| ... | ... | @@ -254,7 +255,7 @@ TEST_CASE_METHOD(TApp, "CopyableMapMove", "[set]") { |
| 254 | 255 | |
| 255 | 256 | TEST_CASE_METHOD(TApp, "SimpleSets", "[set]") { |
| 256 | 257 | std::string value; |
| 257 | - auto opt = app.add_option("-s,--set", value)->check(CLI::IsMember{std::set<std::string>({"one", "two", "three"})}); | |
| 258 | + auto *opt = app.add_option("-s,--set", value)->check(CLI::IsMember{std::set<std::string>({"one", "two", "three"})}); | |
| 258 | 259 | args = {"-s", "one"}; |
| 259 | 260 | run(); |
| 260 | 261 | CHECK(app.count("-s") == 1u); |
| ... | ... | @@ -264,9 +265,9 @@ TEST_CASE_METHOD(TApp, "SimpleSets", "[set]") { |
| 264 | 265 | } |
| 265 | 266 | |
| 266 | 267 | TEST_CASE_METHOD(TApp, "SimpleSetsPtrs", "[set]") { |
| 267 | - auto set = std::shared_ptr<std::set<std::string>>(new std::set<std::string>{"one", "two", "three"}); | |
| 268 | + auto set = std::make_shared<std::set<std::string>>(std::set<std::string>{"one", "two", "three"}); | |
| 268 | 269 | std::string value; |
| 269 | - auto opt = app.add_option("-s,--set", value)->check(CLI::IsMember{set}); | |
| 270 | + auto *opt = app.add_option("-s,--set", value)->check(CLI::IsMember{set}); | |
| 270 | 271 | args = {"-s", "one"}; |
| 271 | 272 | run(); |
| 272 | 273 | CHECK(app.count("-s") == 1u); |
| ... | ... | @@ -286,7 +287,7 @@ TEST_CASE_METHOD(TApp, "SimpleSetsPtrs", "[set]") { |
| 286 | 287 | |
| 287 | 288 | TEST_CASE_METHOD(TApp, "SimiShortcutSets", "[set]") { |
| 288 | 289 | std::string value; |
| 289 | - auto opt = app.add_option("--set", value)->check(CLI::IsMember({"one", "two", "three"})); | |
| 290 | + auto *opt = app.add_option("--set", value)->check(CLI::IsMember({"one", "two", "three"})); | |
| 290 | 291 | args = {"--set", "one"}; |
| 291 | 292 | run(); |
| 292 | 293 | CHECK(app.count("--set") == 1u); |
| ... | ... | @@ -294,7 +295,7 @@ TEST_CASE_METHOD(TApp, "SimiShortcutSets", "[set]") { |
| 294 | 295 | CHECK("one" == value); |
| 295 | 296 | |
| 296 | 297 | std::string value2; |
| 297 | - auto opt2 = app.add_option("--set2", value2)->transform(CLI::IsMember({"One", "two", "three"}, CLI::ignore_case)); | |
| 298 | + auto *opt2 = app.add_option("--set2", value2)->transform(CLI::IsMember({"One", "two", "three"}, CLI::ignore_case)); | |
| 298 | 299 | args = {"--set2", "onE"}; |
| 299 | 300 | run(); |
| 300 | 301 | CHECK(app.count("--set2") == 1u); |
| ... | ... | @@ -302,8 +303,8 @@ TEST_CASE_METHOD(TApp, "SimiShortcutSets", "[set]") { |
| 302 | 303 | CHECK("One" == value2); |
| 303 | 304 | |
| 304 | 305 | std::string value3; |
| 305 | - auto opt3 = app.add_option("--set3", value3) | |
| 306 | - ->transform(CLI::IsMember({"O_ne", "two", "three"}, CLI::ignore_case, CLI::ignore_underscore)); | |
| 306 | + auto *opt3 = app.add_option("--set3", value3) | |
| 307 | + ->transform(CLI::IsMember({"O_ne", "two", "three"}, CLI::ignore_case, CLI::ignore_underscore)); | |
| 307 | 308 | args = {"--set3", "onE"}; |
| 308 | 309 | run(); |
| 309 | 310 | CHECK(app.count("--set3") == 1u); |
| ... | ... | @@ -312,10 +313,10 @@ TEST_CASE_METHOD(TApp, "SimiShortcutSets", "[set]") { |
| 312 | 313 | } |
| 313 | 314 | |
| 314 | 315 | TEST_CASE_METHOD(TApp, "SetFromCharStarArrayVector", "[set]") { |
| 315 | - constexpr const char *names[3]{"one", "two", "three"}; | |
| 316 | + constexpr const char *names[3]{"one", "two", "three"}; // NOLINT(modernize-avoid-c-arrays) | |
| 316 | 317 | std::string value; |
| 317 | - auto opt = app.add_option("-s,--set", value) | |
| 318 | - ->check(CLI::IsMember{std::vector<std::string>(std::begin(names), std::end(names))}); | |
| 318 | + auto *opt = app.add_option("-s,--set", value) | |
| 319 | + ->check(CLI::IsMember{std::vector<std::string>(std::begin(names), std::end(names))}); | |
| 319 | 320 | args = {"-s", "one"}; |
| 320 | 321 | run(); |
| 321 | 322 | CHECK(app.count("-s") == 1u); |
| ... | ... | @@ -327,7 +328,7 @@ TEST_CASE_METHOD(TApp, "SetFromCharStarArrayVector", "[set]") { |
| 327 | 328 | TEST_CASE_METHOD(TApp, "OtherTypeSets", "[set]") { |
| 328 | 329 | int value{0}; |
| 329 | 330 | std::vector<int> set = {2, 3, 4}; |
| 330 | - auto opt = app.add_option("--set", value)->check(CLI::IsMember(set)); | |
| 331 | + auto *opt = app.add_option("--set", value)->check(CLI::IsMember(set)); | |
| 331 | 332 | args = {"--set", "3"}; |
| 332 | 333 | run(); |
| 333 | 334 | CHECK(app.count("--set") == 1u); |
| ... | ... | @@ -338,7 +339,7 @@ TEST_CASE_METHOD(TApp, "OtherTypeSets", "[set]") { |
| 338 | 339 | CHECK_THROWS_AS(run(), CLI::ValidationError); |
| 339 | 340 | |
| 340 | 341 | std::vector<int> set2 = {-2, 3, 4}; |
| 341 | - auto opt2 = app.add_option("--set2", value)->transform(CLI::IsMember(set2, [](int x) { return std::abs(x); })); | |
| 342 | + auto *opt2 = app.add_option("--set2", value)->transform(CLI::IsMember(set2, [](int x) { return std::abs(x); })); | |
| 342 | 343 | args = {"--set2", "-3"}; |
| 343 | 344 | run(); |
| 344 | 345 | CHECK(app.count("--set2") == 1u); |
| ... | ... | @@ -360,7 +361,7 @@ TEST_CASE_METHOD(TApp, "OtherTypeSets", "[set]") { |
| 360 | 361 | |
| 361 | 362 | TEST_CASE_METHOD(TApp, "NumericalSets", "[set]") { |
| 362 | 363 | int value{0}; |
| 363 | - auto opt = app.add_option("-s,--set", value)->check(CLI::IsMember{std::set<int>({1, 2, 3})}); | |
| 364 | + auto *opt = app.add_option("-s,--set", value)->check(CLI::IsMember{std::set<int>({1, 2, 3})}); | |
| 364 | 365 | args = {"-s", "1"}; |
| 365 | 366 | run(); |
| 366 | 367 | CHECK(app.count("-s") == 1u); |
| ... | ... | @@ -494,7 +495,7 @@ TEST_CASE_METHOD(TApp, "FailSet", "[set]") { |
| 494 | 495 | TEST_CASE_METHOD(TApp, "FailMutableSet", "[set]") { |
| 495 | 496 | |
| 496 | 497 | int choice{0}; |
| 497 | - auto vals = std::shared_ptr<std::set<int>>(new std::set<int>({1, 2, 3})); | |
| 498 | + auto vals = std::make_shared<std::set<int>>(std::set<int>{1, 2, 3}); | |
| 498 | 499 | app.add_option("-q,--quick", choice)->check(CLI::IsMember(vals)); |
| 499 | 500 | app.add_option("-s,--slow", choice)->capture_default_str()->check(CLI::IsMember(vals)); |
| 500 | 501 | |
| ... | ... | @@ -554,7 +555,7 @@ TEST_CASE_METHOD(TApp, "InSetIgnoreCaseMutableValue", "[set]") { |
| 554 | 555 | |
| 555 | 556 | TEST_CASE_METHOD(TApp, "InSetIgnoreCasePointer", "[set]") { |
| 556 | 557 | |
| 557 | - std::set<std::string> *options = new std::set<std::string>{"one", "Two", "THREE"}; | |
| 558 | + auto *options = new std::set<std::string>{"one", "Two", "THREE"}; | |
| 558 | 559 | std::string choice; |
| 559 | 560 | app.add_option("-q,--quick", choice)->transform(CLI::IsMember(*options, CLI::ignore_case)); |
| 560 | 561 | |
| ... | ... | @@ -584,7 +585,7 @@ TEST_CASE_METHOD(TApp, "InSetIgnoreCasePointer", "[set]") { |
| 584 | 585 | |
| 585 | 586 | TEST_CASE_METHOD(TApp, "NotInSetIgnoreCasePointer", "[set]") { |
| 586 | 587 | |
| 587 | - std::set<std::string> *options = new std::set<std::string>{"one", "Two", "THREE"}; | |
| 588 | + auto *options = new std::set<std::string>{"one", "Two", "THREE"}; | |
| 588 | 589 | std::string choice; |
| 589 | 590 | app.add_option("-q,--quick", choice)->check(!CLI::IsMember(*options, CLI::ignore_case)); |
| 590 | 591 | ... | ... |
tests/StringParseTest.cpp
| ... | ... | @@ -24,7 +24,7 @@ TEST_CASE_METHOD(TApp, "ExistingExeCheck", "[stringparse]") { |
| 24 | 24 | } |
| 25 | 25 | |
| 26 | 26 | app.parse(std::string("./") + std::string(tmpexe) + |
| 27 | - " --string=\"this is my quoted string\" -t 'qstring 2' -m=`\"quoted string\"`", | |
| 27 | + R"( --string="this is my quoted string" -t 'qstring 2' -m=`"quoted string"`)", | |
| 28 | 28 | true); |
| 29 | 29 | CHECK("this is my quoted string" == str); |
| 30 | 30 | CHECK("qstring 2" == str2); |
| ... | ... | @@ -46,7 +46,7 @@ TEST_CASE_METHOD(TApp, "ExistingExeCheckWithSpace", "[stringparse]") { |
| 46 | 46 | } |
| 47 | 47 | |
| 48 | 48 | app.parse(std::string("./") + std::string(tmpexe) + |
| 49 | - " --string=\"this is my quoted string\" -t 'qstring 2' -m=`\"quoted string\"`", | |
| 49 | + R"( --string="this is my quoted string" -t 'qstring 2' -m=`"quoted string"`)", | |
| 50 | 50 | true); |
| 51 | 51 | CHECK("this is my quoted string" == str); |
| 52 | 52 | CHECK("qstring 2" == str2); |
| ... | ... | @@ -70,7 +70,7 @@ TEST_CASE_METHOD(TApp, "ExistingExeCheckWithLotsOfSpace", "[stringparse]") { |
| 70 | 70 | } |
| 71 | 71 | |
| 72 | 72 | app.parse(std::string("./") + std::string(tmpexe) + |
| 73 | - " --string=\"this is my quoted string\" -t 'qstring 2' -m=`\"quoted string\"`", | |
| 73 | + R"( --string="this is my quoted string" -t 'qstring 2' -m=`"quoted string"`)", | |
| 74 | 74 | true); |
| 75 | 75 | CHECK("this is my quoted string" == str); |
| 76 | 76 | CHECK("qstring 2" == str2); | ... | ... |
tests/SubcommandTest.cpp
| ... | ... | @@ -11,8 +11,8 @@ using Catch::Matchers::Contains; |
| 11 | 11 | using vs_t = std::vector<std::string>; |
| 12 | 12 | |
| 13 | 13 | TEST_CASE_METHOD(TApp, "BasicSubcommands", "[subcom]") { |
| 14 | - auto sub1 = app.add_subcommand("sub1"); | |
| 15 | - auto sub2 = app.add_subcommand("sub2"); | |
| 14 | + auto *sub1 = app.add_subcommand("sub1"); | |
| 15 | + auto *sub2 = app.add_subcommand("sub2"); | |
| 16 | 16 | |
| 17 | 17 | CHECK(&app == sub1->get_parent()); |
| 18 | 18 | |
| ... | ... | @@ -21,7 +21,7 @@ TEST_CASE_METHOD(TApp, "BasicSubcommands", "[subcom]") { |
| 21 | 21 | CHECK_THROWS_AS(app.get_subcommand("sub3"), CLI::OptionNotFound); |
| 22 | 22 | |
| 23 | 23 | run(); |
| 24 | - CHECK(app.get_subcommands().size() == 0u); | |
| 24 | + CHECK(app.get_subcommands().empty()); | |
| 25 | 25 | |
| 26 | 26 | args = {"sub1"}; |
| 27 | 27 | run(); |
| ... | ... | @@ -29,7 +29,7 @@ TEST_CASE_METHOD(TApp, "BasicSubcommands", "[subcom]") { |
| 29 | 29 | CHECK(app.get_subcommands().size() == 1u); |
| 30 | 30 | |
| 31 | 31 | app.clear(); |
| 32 | - CHECK(app.get_subcommands().size() == 0u); | |
| 32 | + CHECK(app.get_subcommands().empty()); | |
| 33 | 33 | |
| 34 | 34 | args = {"sub2"}; |
| 35 | 35 | run(); |
| ... | ... | @@ -57,8 +57,8 @@ TEST_CASE_METHOD(TApp, "BasicSubcommands", "[subcom]") { |
| 57 | 57 | TEST_CASE_METHOD(TApp, "MultiSubFallthrough", "[subcom]") { |
| 58 | 58 | |
| 59 | 59 | // No explicit fallthrough |
| 60 | - auto sub1 = app.add_subcommand("sub1"); | |
| 61 | - auto sub2 = app.add_subcommand("sub2"); | |
| 60 | + auto *sub1 = app.add_subcommand("sub1"); | |
| 61 | + auto *sub2 = app.add_subcommand("sub2"); | |
| 62 | 62 | |
| 63 | 63 | args = {"sub1", "sub2"}; |
| 64 | 64 | run(); |
| ... | ... | @@ -96,7 +96,7 @@ TEST_CASE_METHOD(TApp, "MultiSubFallthrough", "[subcom]") { |
| 96 | 96 | } |
| 97 | 97 | |
| 98 | 98 | TEST_CASE_METHOD(TApp, "CrazyNameSubcommand", "[subcom]") { |
| 99 | - auto sub1 = app.add_subcommand("sub1"); | |
| 99 | + auto *sub1 = app.add_subcommand("sub1"); | |
| 100 | 100 | // name can be set to whatever |
| 101 | 101 | CHECK_NOTHROW(sub1->name("crazy name with spaces")); |
| 102 | 102 | args = {"crazy name with spaces"}; |
| ... | ... | @@ -110,8 +110,8 @@ TEST_CASE_METHOD(TApp, "RequiredAndSubcommands", "[subcom]") { |
| 110 | 110 | |
| 111 | 111 | std::string baz; |
| 112 | 112 | app.add_option("baz", baz, "Baz Description")->required()->capture_default_str(); |
| 113 | - auto foo = app.add_subcommand("foo"); | |
| 114 | - auto bar = app.add_subcommand("bar"); | |
| 113 | + auto *foo = app.add_subcommand("foo"); | |
| 114 | + auto *bar = app.add_subcommand("bar"); | |
| 115 | 115 | |
| 116 | 116 | args = {"bar", "foo"}; |
| 117 | 117 | REQUIRE_NOTHROW(run()); |
| ... | ... | @@ -138,7 +138,7 @@ TEST_CASE_METHOD(TApp, "RequiredAndSubcomFallthrough", "[subcom]") { |
| 138 | 138 | std::string baz; |
| 139 | 139 | app.add_option("baz", baz)->required(); |
| 140 | 140 | app.add_subcommand("foo"); |
| 141 | - auto bar = app.add_subcommand("bar"); | |
| 141 | + auto *bar = app.add_subcommand("bar"); | |
| 142 | 142 | app.fallthrough(); |
| 143 | 143 | |
| 144 | 144 | args = {"other", "bar"}; |
| ... | ... | @@ -153,16 +153,16 @@ TEST_CASE_METHOD(TApp, "RequiredAndSubcomFallthrough", "[subcom]") { |
| 153 | 153 | TEST_CASE_METHOD(TApp, "FooFooProblem", "[subcom]") { |
| 154 | 154 | |
| 155 | 155 | std::string baz_str, other_str; |
| 156 | - auto baz = app.add_option("baz", baz_str); | |
| 157 | - auto foo = app.add_subcommand("foo"); | |
| 158 | - auto other = foo->add_option("other", other_str); | |
| 156 | + auto *baz = app.add_option("baz", baz_str); | |
| 157 | + auto *foo = app.add_subcommand("foo"); | |
| 158 | + auto *other = foo->add_option("other", other_str); | |
| 159 | 159 | |
| 160 | 160 | args = {"foo", "foo"}; |
| 161 | 161 | run(); |
| 162 | 162 | CHECK(*foo); |
| 163 | 163 | CHECK(!*baz); |
| 164 | 164 | CHECK(*other); |
| 165 | - CHECK("" == baz_str); | |
| 165 | + CHECK(baz_str.empty()); | |
| 166 | 166 | CHECK("foo" == other_str); |
| 167 | 167 | |
| 168 | 168 | baz_str = ""; |
| ... | ... | @@ -173,12 +173,12 @@ TEST_CASE_METHOD(TApp, "FooFooProblem", "[subcom]") { |
| 173 | 173 | CHECK(*baz); |
| 174 | 174 | CHECK(!*other); |
| 175 | 175 | CHECK("foo" == baz_str); |
| 176 | - CHECK("" == other_str); | |
| 176 | + CHECK(other_str.empty()); | |
| 177 | 177 | } |
| 178 | 178 | |
| 179 | 179 | TEST_CASE_METHOD(TApp, "DuplicateSubcommands", "[subcom]") { |
| 180 | 180 | |
| 181 | - auto foo = app.add_subcommand("foo"); | |
| 181 | + auto *foo = app.add_subcommand("foo"); | |
| 182 | 182 | |
| 183 | 183 | args = {"foo", "foo"}; |
| 184 | 184 | run(); |
| ... | ... | @@ -193,7 +193,7 @@ TEST_CASE_METHOD(TApp, "DuplicateSubcommands", "[subcom]") { |
| 193 | 193 | |
| 194 | 194 | TEST_CASE_METHOD(TApp, "DuplicateSubcommandCallbacks", "[subcom]") { |
| 195 | 195 | |
| 196 | - auto foo = app.add_subcommand("foo"); | |
| 196 | + auto *foo = app.add_subcommand("foo"); | |
| 197 | 197 | int count{0}; |
| 198 | 198 | foo->callback([&count]() { ++count; }); |
| 199 | 199 | foo->immediate_callback(); |
| ... | ... | @@ -209,7 +209,7 @@ TEST_CASE_METHOD(TApp, "DuplicateSubcommandCallbacks", "[subcom]") { |
| 209 | 209 | |
| 210 | 210 | TEST_CASE_METHOD(TApp, "DuplicateSubcommandCallbacksValues", "[subcom]") { |
| 211 | 211 | |
| 212 | - auto foo = app.add_subcommand("foo"); | |
| 212 | + auto *foo = app.add_subcommand("foo"); | |
| 213 | 213 | int val{0}; |
| 214 | 214 | foo->add_option("--val", val); |
| 215 | 215 | std::vector<int> vals; |
| ... | ... | @@ -230,9 +230,9 @@ TEST_CASE_METHOD(TApp, "DuplicateSubcommandCallbacksValues", "[subcom]") { |
| 230 | 230 | } |
| 231 | 231 | |
| 232 | 232 | TEST_CASE_METHOD(TApp, "Callbacks", "[subcom]") { |
| 233 | - auto sub1 = app.add_subcommand("sub1"); | |
| 233 | + auto *sub1 = app.add_subcommand("sub1"); | |
| 234 | 234 | sub1->callback([]() { throw CLI::Success(); }); |
| 235 | - auto sub2 = app.add_subcommand("sub2"); | |
| 235 | + auto *sub2 = app.add_subcommand("sub2"); | |
| 236 | 236 | bool val{false}; |
| 237 | 237 | sub2->callback([&val]() { val = true; }); |
| 238 | 238 | |
| ... | ... | @@ -245,15 +245,15 @@ TEST_CASE_METHOD(TApp, "Callbacks", "[subcom]") { |
| 245 | 245 | TEST_CASE_METHOD(TApp, "CallbackOrder", "[subcom]") { |
| 246 | 246 | |
| 247 | 247 | std::vector<std::string> cb; |
| 248 | - app.parse_complete_callback([&cb]() { cb.push_back("ac1"); }); | |
| 249 | - app.final_callback([&cb]() { cb.push_back("ac2"); }); | |
| 250 | - auto sub1 = | |
| 248 | + app.parse_complete_callback([&cb]() { cb.emplace_back("ac1"); }); | |
| 249 | + app.final_callback([&cb]() { cb.emplace_back("ac2"); }); | |
| 250 | + auto *sub1 = | |
| 251 | 251 | app.add_subcommand("sub1") |
| 252 | - ->parse_complete_callback([&cb]() { cb.push_back("c1"); }) | |
| 252 | + ->parse_complete_callback([&cb]() { cb.emplace_back("c1"); }) | |
| 253 | 253 | ->preparse_callback([&cb](std::size_t v1) { cb.push_back(std::string("pc1-") + std::to_string(v1)); }); |
| 254 | - auto sub2 = | |
| 254 | + auto *sub2 = | |
| 255 | 255 | app.add_subcommand("sub2") |
| 256 | - ->final_callback([&cb]() { cb.push_back("c2"); }) | |
| 256 | + ->final_callback([&cb]() { cb.emplace_back("c2"); }) | |
| 257 | 257 | ->preparse_callback([&cb](std::size_t v1) { cb.push_back(std::string("pc2-") + std::to_string(v1)); }); |
| 258 | 258 | app.preparse_callback([&cb](std::size_t v1) { cb.push_back(std::string("pa-") + std::to_string(v1)); }); |
| 259 | 259 | |
| ... | ... | @@ -291,9 +291,9 @@ TEST_CASE_METHOD(TApp, "CallbackOrder", "[subcom]") { |
| 291 | 291 | TEST_CASE_METHOD(TApp, "CallbackOrder2", "[subcom]") { |
| 292 | 292 | |
| 293 | 293 | std::vector<std::string> cb; |
| 294 | - app.add_subcommand("sub1")->parse_complete_callback([&cb]() { cb.push_back("sub1"); }); | |
| 295 | - app.add_subcommand("sub2")->parse_complete_callback([&cb]() { cb.push_back("sub2"); }); | |
| 296 | - app.add_subcommand("sub3")->parse_complete_callback([&cb]() { cb.push_back("sub3"); }); | |
| 294 | + app.add_subcommand("sub1")->parse_complete_callback([&cb]() { cb.emplace_back("sub1"); }); | |
| 295 | + app.add_subcommand("sub2")->parse_complete_callback([&cb]() { cb.emplace_back("sub2"); }); | |
| 296 | + app.add_subcommand("sub3")->parse_complete_callback([&cb]() { cb.emplace_back("sub3"); }); | |
| 297 | 297 | |
| 298 | 298 | args = {"sub1", "sub2", "sub3", "sub1", "sub1", "sub2", "sub1"}; |
| 299 | 299 | run(); |
| ... | ... | @@ -311,9 +311,9 @@ TEST_CASE_METHOD(TApp, "CallbackOrder2_withFallthrough", "[subcom]") { |
| 311 | 311 | |
| 312 | 312 | std::vector<std::string> cb; |
| 313 | 313 | |
| 314 | - app.add_subcommand("sub1")->parse_complete_callback([&cb]() { cb.push_back("sub1"); })->fallthrough(); | |
| 315 | - app.add_subcommand("sub2")->parse_complete_callback([&cb]() { cb.push_back("sub2"); }); | |
| 316 | - app.add_subcommand("sub3")->parse_complete_callback([&cb]() { cb.push_back("sub3"); }); | |
| 314 | + app.add_subcommand("sub1")->parse_complete_callback([&cb]() { cb.emplace_back("sub1"); })->fallthrough(); | |
| 315 | + app.add_subcommand("sub2")->parse_complete_callback([&cb]() { cb.emplace_back("sub2"); }); | |
| 316 | + app.add_subcommand("sub3")->parse_complete_callback([&cb]() { cb.emplace_back("sub3"); }); | |
| 317 | 317 | |
| 318 | 318 | args = {"sub1", "sub2", "sub3", "sub1", "sub1", "sub2", "sub1"}; |
| 319 | 319 | run(); |
| ... | ... | @@ -328,9 +328,9 @@ TEST_CASE_METHOD(TApp, "CallbackOrder2_withFallthrough", "[subcom]") { |
| 328 | 328 | } |
| 329 | 329 | |
| 330 | 330 | TEST_CASE_METHOD(TApp, "RuntimeErrorInCallback", "[subcom]") { |
| 331 | - auto sub1 = app.add_subcommand("sub1"); | |
| 331 | + auto *sub1 = app.add_subcommand("sub1"); | |
| 332 | 332 | sub1->callback([]() { throw CLI::RuntimeError(); }); |
| 333 | - auto sub2 = app.add_subcommand("sub2"); | |
| 333 | + auto *sub2 = app.add_subcommand("sub2"); | |
| 334 | 334 | sub2->callback([]() { throw CLI::RuntimeError(2); }); |
| 335 | 335 | |
| 336 | 336 | args = {"sub1"}; |
| ... | ... | @@ -403,7 +403,7 @@ TEST_CASE_METHOD(TApp, "NoFallThroughPositionalsWithTerminator", "[subcom]") { |
| 403 | 403 | |
| 404 | 404 | TEST_CASE_METHOD(TApp, "NamelessSubComPositionals", "[subcom]") { |
| 405 | 405 | |
| 406 | - auto sub = app.add_subcommand(); | |
| 406 | + auto *sub = app.add_subcommand(); | |
| 407 | 407 | int val{1}; |
| 408 | 408 | sub->add_option("val", val); |
| 409 | 409 | |
| ... | ... | @@ -414,8 +414,8 @@ TEST_CASE_METHOD(TApp, "NamelessSubComPositionals", "[subcom]") { |
| 414 | 414 | |
| 415 | 415 | TEST_CASE_METHOD(TApp, "NamelessSubWithSub", "[subcom]") { |
| 416 | 416 | |
| 417 | - auto sub = app.add_subcommand(); | |
| 418 | - auto subsub = sub->add_subcommand("val"); | |
| 417 | + auto *sub = app.add_subcommand(); | |
| 418 | + auto *subsub = sub->add_subcommand("val"); | |
| 419 | 419 | |
| 420 | 420 | args = {"val"}; |
| 421 | 421 | run(); |
| ... | ... | @@ -425,12 +425,12 @@ TEST_CASE_METHOD(TApp, "NamelessSubWithSub", "[subcom]") { |
| 425 | 425 | |
| 426 | 426 | TEST_CASE_METHOD(TApp, "NamelessSubWithMultipleSub", "[subcom]") { |
| 427 | 427 | |
| 428 | - auto sub1 = app.add_subcommand(); | |
| 429 | - auto sub2 = app.add_subcommand(); | |
| 430 | - auto sub1sub1 = sub1->add_subcommand("val1"); | |
| 431 | - auto sub1sub2 = sub1->add_subcommand("val2"); | |
| 432 | - auto sub2sub1 = sub2->add_subcommand("val3"); | |
| 433 | - auto sub2sub2 = sub2->add_subcommand("val4"); | |
| 428 | + auto *sub1 = app.add_subcommand(); | |
| 429 | + auto *sub2 = app.add_subcommand(); | |
| 430 | + auto *sub1sub1 = sub1->add_subcommand("val1"); | |
| 431 | + auto *sub1sub2 = sub1->add_subcommand("val2"); | |
| 432 | + auto *sub2sub1 = sub2->add_subcommand("val3"); | |
| 433 | + auto *sub2sub2 = sub2->add_subcommand("val4"); | |
| 434 | 434 | args = {"val1"}; |
| 435 | 435 | run(); |
| 436 | 436 | CHECK(sub1sub1->parsed()); |
| ... | ... | @@ -461,12 +461,12 @@ TEST_CASE_METHOD(TApp, "NamelessSubWithMultipleSub", "[subcom]") { |
| 461 | 461 | |
| 462 | 462 | TEST_CASE_METHOD(TApp, "Nameless4LayerDeep", "[subcom]") { |
| 463 | 463 | |
| 464 | - auto sub = app.add_subcommand(); | |
| 465 | - auto ssub = sub->add_subcommand(); | |
| 466 | - auto sssub = ssub->add_subcommand(); | |
| 464 | + auto *sub = app.add_subcommand(); | |
| 465 | + auto *ssub = sub->add_subcommand(); | |
| 466 | + auto *sssub = ssub->add_subcommand(); | |
| 467 | 467 | |
| 468 | - auto ssssub = sssub->add_subcommand(); | |
| 469 | - auto sssssub = ssssub->add_subcommand("val"); | |
| 468 | + auto *ssssub = sssub->add_subcommand(); | |
| 469 | + auto *sssssub = ssssub->add_subcommand("val"); | |
| 470 | 470 | |
| 471 | 471 | args = {"val"}; |
| 472 | 472 | run(); |
| ... | ... | @@ -477,13 +477,13 @@ TEST_CASE_METHOD(TApp, "Nameless4LayerDeep", "[subcom]") { |
| 477 | 477 | /// Put subcommands in some crazy pattern and make everything still works |
| 478 | 478 | TEST_CASE_METHOD(TApp, "Nameless4LayerDeepMulti", "[subcom]") { |
| 479 | 479 | |
| 480 | - auto sub1 = app.add_subcommand(); | |
| 481 | - auto sub2 = app.add_subcommand(); | |
| 482 | - auto ssub1 = sub1->add_subcommand(); | |
| 483 | - auto ssub2 = sub2->add_subcommand(); | |
| 480 | + auto *sub1 = app.add_subcommand(); | |
| 481 | + auto *sub2 = app.add_subcommand(); | |
| 482 | + auto *ssub1 = sub1->add_subcommand(); | |
| 483 | + auto *ssub2 = sub2->add_subcommand(); | |
| 484 | 484 | |
| 485 | - auto sssub1 = ssub1->add_subcommand(); | |
| 486 | - auto sssub2 = ssub2->add_subcommand(); | |
| 485 | + auto *sssub1 = ssub1->add_subcommand(); | |
| 486 | + auto *sssub2 = ssub2->add_subcommand(); | |
| 487 | 487 | sssub1->add_subcommand("val1"); |
| 488 | 488 | ssub2->add_subcommand("val2"); |
| 489 | 489 | sub2->add_subcommand("val3"); |
| ... | ... | @@ -568,7 +568,7 @@ TEST_CASE_METHOD(TApp, "EvilParseFallthrough", "[subcom]") { |
| 568 | 568 | int val1{0}, val2{0}; |
| 569 | 569 | app.add_option("--val1", val1); |
| 570 | 570 | |
| 571 | - auto sub = app.add_subcommand("sub"); | |
| 571 | + auto *sub = app.add_subcommand("sub"); | |
| 572 | 572 | sub->add_option("val2", val2); |
| 573 | 573 | |
| 574 | 574 | args = {"sub", "--val1", "1", "2"}; |
| ... | ... | @@ -584,7 +584,7 @@ TEST_CASE_METHOD(TApp, "CallbackOrdering", "[subcom]") { |
| 584 | 584 | int val{1}, sub_val{0}; |
| 585 | 585 | app.add_option("--val", val); |
| 586 | 586 | |
| 587 | - auto sub = app.add_subcommand("sub"); | |
| 587 | + auto *sub = app.add_subcommand("sub"); | |
| 588 | 588 | sub->callback([&val, &sub_val]() { sub_val = val; }); |
| 589 | 589 | |
| 590 | 590 | args = {"sub", "--val=2"}; |
| ... | ... | @@ -603,7 +603,7 @@ TEST_CASE_METHOD(TApp, "CallbackOrderingImmediate", "[subcom]") { |
| 603 | 603 | int val{1}, sub_val{0}; |
| 604 | 604 | app.add_option("--val", val); |
| 605 | 605 | |
| 606 | - auto sub = app.add_subcommand("sub")->immediate_callback(); | |
| 606 | + auto *sub = app.add_subcommand("sub")->immediate_callback(); | |
| 607 | 607 | sub->callback([&val, &sub_val]() { sub_val = val; }); |
| 608 | 608 | |
| 609 | 609 | args = {"sub", "--val=2"}; |
| ... | ... | @@ -621,7 +621,7 @@ TEST_CASE_METHOD(TApp, "CallbackOrderingImmediateMain", "[subcom]") { |
| 621 | 621 | app.fallthrough(); |
| 622 | 622 | int val{0}, sub_val{0}; |
| 623 | 623 | |
| 624 | - auto sub = app.add_subcommand("sub"); | |
| 624 | + auto *sub = app.add_subcommand("sub"); | |
| 625 | 625 | sub->callback([&val, &sub_val]() { |
| 626 | 626 | sub_val = val; |
| 627 | 627 | val = 2; |
| ... | ... | @@ -652,7 +652,7 @@ TEST_CASE_METHOD(TApp, "CallbackOrderingImmediateModeOrder", "[subcom]") { |
| 652 | 652 | std::vector<int> v; |
| 653 | 653 | app.callback([&v]() { v.push_back(1); })->immediate_callback(true); |
| 654 | 654 | |
| 655 | - auto sub = app.add_subcommand("hello")->callback([&v]() { v.push_back(2); })->immediate_callback(false); | |
| 655 | + auto *sub = app.add_subcommand("hello")->callback([&v]() { v.push_back(2); })->immediate_callback(false); | |
| 656 | 656 | args = {"hello"}; |
| 657 | 657 | run(); |
| 658 | 658 | // immediate_callback inherited |
| ... | ... | @@ -682,21 +682,21 @@ TEST_CASE_METHOD(TApp, "RequiredSubCom", "[subcom]") { |
| 682 | 682 | |
| 683 | 683 | TEST_CASE_METHOD(TApp, "SubComExtras", "[subcom]") { |
| 684 | 684 | app.allow_extras(); |
| 685 | - auto sub = app.add_subcommand("sub"); | |
| 685 | + auto *sub = app.add_subcommand("sub"); | |
| 686 | 686 | |
| 687 | 687 | args = {"extra", "sub"}; |
| 688 | 688 | run(); |
| 689 | 689 | CHECK(std::vector<std::string>({"extra"}) == app.remaining()); |
| 690 | - CHECK(std::vector<std::string>() == sub->remaining()); | |
| 690 | + CHECK(sub->remaining().empty()); | |
| 691 | 691 | |
| 692 | 692 | args = {"extra1", "extra2", "sub"}; |
| 693 | 693 | run(); |
| 694 | 694 | CHECK(std::vector<std::string>({"extra1", "extra2"}) == app.remaining()); |
| 695 | - CHECK(std::vector<std::string>() == sub->remaining()); | |
| 695 | + CHECK(sub->remaining().empty()); | |
| 696 | 696 | |
| 697 | 697 | args = {"sub", "extra1", "extra2"}; |
| 698 | 698 | run(); |
| 699 | - CHECK(std::vector<std::string>() == app.remaining()); | |
| 699 | + CHECK(app.remaining().empty()); | |
| 700 | 700 | CHECK(std::vector<std::string>({"extra1", "extra2"}) == sub->remaining()); |
| 701 | 701 | |
| 702 | 702 | args = {"extra1", "extra2", "sub", "extra3", "extra4"}; |
| ... | ... | @@ -723,8 +723,8 @@ TEST_CASE_METHOD(TApp, "Required1SubCom", "[subcom]") { |
| 723 | 723 | |
| 724 | 724 | TEST_CASE_METHOD(TApp, "BadSubcommandSearch", "[subcom]") { |
| 725 | 725 | |
| 726 | - auto one = app.add_subcommand("one"); | |
| 727 | - auto two = one->add_subcommand("two"); | |
| 726 | + auto *one = app.add_subcommand("one"); | |
| 727 | + auto *two = one->add_subcommand("two"); | |
| 728 | 728 | |
| 729 | 729 | CHECK_THROWS_AS(app.get_subcommand(two), CLI::OptionNotFound); |
| 730 | 730 | CHECK_THROWS_AS(app.get_subcommand_ptr(two), CLI::OptionNotFound); |
| ... | ... | @@ -770,7 +770,7 @@ TEST_CASE_METHOD(TApp, "PrefixSeparation", "[subcom]") { |
| 770 | 770 | } |
| 771 | 771 | |
| 772 | 772 | TEST_CASE_METHOD(TApp, "PrefixSubcom", "[subcom]") { |
| 773 | - auto subc = app.add_subcommand("subc"); | |
| 773 | + auto *subc = app.add_subcommand("subc"); | |
| 774 | 774 | subc->prefix_command(); |
| 775 | 775 | |
| 776 | 776 | app.add_flag("--simple"); |
| ... | ... | @@ -785,7 +785,7 @@ TEST_CASE_METHOD(TApp, "PrefixSubcom", "[subcom]") { |
| 785 | 785 | |
| 786 | 786 | TEST_CASE_METHOD(TApp, "InheritHelpAllFlag", "[subcom]") { |
| 787 | 787 | app.set_help_all_flag("--help-all"); |
| 788 | - auto subc = app.add_subcommand("subc"); | |
| 788 | + auto *subc = app.add_subcommand("subc"); | |
| 789 | 789 | auto help_opt_list = subc->get_options([](const CLI::Option *opt) { return opt->get_name() == "--help-all"; }); |
| 790 | 790 | CHECK(1u == help_opt_list.size()); |
| 791 | 791 | } |
| ... | ... | @@ -908,11 +908,11 @@ TEST_CASE_METHOD(SubcommandProgram, "Subcommand CaseCheck", "[subcom]") { |
| 908 | 908 | |
| 909 | 909 | TEST_CASE_METHOD(TApp, "SubcomInheritCaseCheck", "[subcom]") { |
| 910 | 910 | app.ignore_case(); |
| 911 | - auto sub1 = app.add_subcommand("sub1"); | |
| 912 | - auto sub2 = app.add_subcommand("sub2"); | |
| 911 | + auto *sub1 = app.add_subcommand("sub1"); | |
| 912 | + auto *sub2 = app.add_subcommand("sub2"); | |
| 913 | 913 | |
| 914 | 914 | run(); |
| 915 | - CHECK(app.get_subcommands().size() == 0u); | |
| 915 | + CHECK(app.get_subcommands().empty()); | |
| 916 | 916 | CHECK(app.get_subcommands({}).size() == 2u); |
| 917 | 917 | CHECK(app.get_subcommands([](const CLI::App *s) { return s->get_name() == "sub1"; }).size() == 1u); |
| 918 | 918 | |
| ... | ... | @@ -922,7 +922,7 @@ TEST_CASE_METHOD(TApp, "SubcomInheritCaseCheck", "[subcom]") { |
| 922 | 922 | CHECK(app.get_subcommands().size() == 1u); |
| 923 | 923 | |
| 924 | 924 | app.clear(); |
| 925 | - CHECK(app.get_subcommands().size() == 0u); | |
| 925 | + CHECK(app.get_subcommands().empty()); | |
| 926 | 926 | |
| 927 | 927 | args = {"sUb2"}; |
| 928 | 928 | run(); |
| ... | ... | @@ -945,11 +945,11 @@ TEST_CASE_METHOD(SubcommandProgram, "Subcommand UnderscoreCheck", "[subcom]") { |
| 945 | 945 | |
| 946 | 946 | TEST_CASE_METHOD(TApp, "SubcomInheritUnderscoreCheck", "[subcom]") { |
| 947 | 947 | app.ignore_underscore(); |
| 948 | - auto sub1 = app.add_subcommand("sub_option1"); | |
| 949 | - auto sub2 = app.add_subcommand("sub_option2"); | |
| 948 | + auto *sub1 = app.add_subcommand("sub_option1"); | |
| 949 | + auto *sub2 = app.add_subcommand("sub_option2"); | |
| 950 | 950 | |
| 951 | 951 | run(); |
| 952 | - CHECK(app.get_subcommands().size() == 0u); | |
| 952 | + CHECK(app.get_subcommands().empty()); | |
| 953 | 953 | CHECK(app.get_subcommands({}).size() == 2u); |
| 954 | 954 | CHECK(app.get_subcommands([](const CLI::App *s) { return s->get_name() == "sub_option1"; }).size() == 1u); |
| 955 | 955 | |
| ... | ... | @@ -959,7 +959,7 @@ TEST_CASE_METHOD(TApp, "SubcomInheritUnderscoreCheck", "[subcom]") { |
| 959 | 959 | CHECK(app.get_subcommands().size() == 1u); |
| 960 | 960 | |
| 961 | 961 | app.clear(); |
| 962 | - CHECK(app.get_subcommands().size() == 0u); | |
| 962 | + CHECK(app.get_subcommands().empty()); | |
| 963 | 963 | |
| 964 | 964 | args = {"_suboption2"}; |
| 965 | 965 | run(); |
| ... | ... | @@ -1160,23 +1160,23 @@ TEST_CASE_METHOD(ManySubcommands, "RemoveSub", "[subcom]") { |
| 1160 | 1160 | } |
| 1161 | 1161 | |
| 1162 | 1162 | TEST_CASE_METHOD(ManySubcommands, "RemoveSubFail", "[subcom]") { |
| 1163 | - auto sub_sub = sub1->add_subcommand("subsub"); | |
| 1163 | + auto *sub_sub = sub1->add_subcommand("subsub"); | |
| 1164 | 1164 | CHECK(!app.remove_subcommand(sub_sub)); |
| 1165 | 1165 | CHECK(sub1->remove_subcommand(sub_sub)); |
| 1166 | 1166 | CHECK(!app.remove_subcommand(nullptr)); |
| 1167 | 1167 | } |
| 1168 | 1168 | |
| 1169 | 1169 | TEST_CASE_METHOD(ManySubcommands, "manyIndexQuery", "[subcom]") { |
| 1170 | - auto s1 = app.get_subcommand(0); | |
| 1171 | - auto s2 = app.get_subcommand(1); | |
| 1172 | - auto s3 = app.get_subcommand(2); | |
| 1173 | - auto s4 = app.get_subcommand(3); | |
| 1170 | + auto *s1 = app.get_subcommand(0); | |
| 1171 | + auto *s2 = app.get_subcommand(1); | |
| 1172 | + auto *s3 = app.get_subcommand(2); | |
| 1173 | + auto *s4 = app.get_subcommand(3); | |
| 1174 | 1174 | CHECK(sub1 == s1); |
| 1175 | 1175 | CHECK(sub2 == s2); |
| 1176 | 1176 | CHECK(sub3 == s3); |
| 1177 | 1177 | CHECK(sub4 == s4); |
| 1178 | 1178 | CHECK_THROWS_AS(app.get_subcommand(4), CLI::OptionNotFound); |
| 1179 | - auto s0 = app.get_subcommand(); | |
| 1179 | + auto *s0 = app.get_subcommand(); | |
| 1180 | 1180 | CHECK(sub1 == s0); |
| 1181 | 1181 | } |
| 1182 | 1182 | |
| ... | ... | @@ -1220,17 +1220,17 @@ TEST_CASE_METHOD(ManySubcommands, "Required2Fuzzy", "[subcom]") { |
| 1220 | 1220 | |
| 1221 | 1221 | TEST_CASE_METHOD(ManySubcommands, "Unlimited", "[subcom]") { |
| 1222 | 1222 | run(); |
| 1223 | - CHECK(vs_t() == app.remaining(true)); | |
| 1223 | + CHECK(app.remaining(true).empty()); | |
| 1224 | 1224 | |
| 1225 | 1225 | app.require_subcommand(); |
| 1226 | 1226 | |
| 1227 | 1227 | run(); |
| 1228 | - CHECK(vs_t() == app.remaining(true)); | |
| 1228 | + CHECK(app.remaining(true).empty()); | |
| 1229 | 1229 | |
| 1230 | 1230 | app.require_subcommand(2, 0); // 2 or more |
| 1231 | 1231 | |
| 1232 | 1232 | run(); |
| 1233 | - CHECK(vs_t() == app.remaining(true)); | |
| 1233 | + CHECK(app.remaining(true).empty()); | |
| 1234 | 1234 | } |
| 1235 | 1235 | |
| 1236 | 1236 | TEST_CASE_METHOD(ManySubcommands, "HelpFlags", "[subcom]") { |
| ... | ... | @@ -1296,7 +1296,7 @@ TEST_CASE_METHOD(ManySubcommands, "SubcommandExclusion", "[subcom]") { |
| 1296 | 1296 | |
| 1297 | 1297 | TEST_CASE_METHOD(ManySubcommands, "SubcommandOptionExclusion", "[subcom]") { |
| 1298 | 1298 | |
| 1299 | - auto excluder_flag = app.add_flag("--exclude"); | |
| 1299 | + auto *excluder_flag = app.add_flag("--exclude"); | |
| 1300 | 1300 | sub1->excludes(excluder_flag)->fallthrough(); |
| 1301 | 1301 | sub2->excludes(excluder_flag)->fallthrough(); |
| 1302 | 1302 | sub3->fallthrough(); |
| ... | ... | @@ -1347,7 +1347,7 @@ TEST_CASE_METHOD(ManySubcommands, "SubcommandNeeds", "[subcom]") { |
| 1347 | 1347 | |
| 1348 | 1348 | TEST_CASE_METHOD(ManySubcommands, "SubcommandNeedsOptions", "[subcom]") { |
| 1349 | 1349 | |
| 1350 | - auto opt = app.add_flag("--subactive"); | |
| 1350 | + auto *opt = app.add_flag("--subactive"); | |
| 1351 | 1351 | sub1->needs(opt); |
| 1352 | 1352 | sub1->fallthrough(); |
| 1353 | 1353 | args = {"sub1", "--subactive"}; |
| ... | ... | @@ -1359,7 +1359,7 @@ TEST_CASE_METHOD(ManySubcommands, "SubcommandNeedsOptions", "[subcom]") { |
| 1359 | 1359 | args = {"--subactive"}; |
| 1360 | 1360 | CHECK_NOTHROW(run()); |
| 1361 | 1361 | |
| 1362 | - auto opt2 = app.add_flag("--subactive2"); | |
| 1362 | + auto *opt2 = app.add_flag("--subactive2"); | |
| 1363 | 1363 | |
| 1364 | 1364 | sub1->needs(opt2); |
| 1365 | 1365 | args = {"sub1", "--subactive"}; |
| ... | ... | @@ -1375,7 +1375,7 @@ TEST_CASE_METHOD(ManySubcommands, "SubcommandNeedsOptions", "[subcom]") { |
| 1375 | 1375 | |
| 1376 | 1376 | TEST_CASE_METHOD(ManySubcommands, "SubcommandNeedsOptionsCallbackOrdering", "[subcom]") { |
| 1377 | 1377 | int count{0}; |
| 1378 | - auto opt = app.add_flag("--subactive"); | |
| 1378 | + auto *opt = app.add_flag("--subactive"); | |
| 1379 | 1379 | app.add_flag("--flag1"); |
| 1380 | 1380 | sub1->needs(opt); |
| 1381 | 1381 | sub1->fallthrough(); |
| ... | ... | @@ -1396,8 +1396,8 @@ TEST_CASE_METHOD(ManySubcommands, "SubcommandNeedsOptionsCallbackOrdering", "[su |
| 1396 | 1396 | |
| 1397 | 1397 | TEST_CASE_METHOD(ManySubcommands, "SubcommandNeedsFail", "[subcom]") { |
| 1398 | 1398 | |
| 1399 | - auto opt = app.add_flag("--subactive"); | |
| 1400 | - auto opt2 = app.add_flag("--dummy"); | |
| 1399 | + auto *opt = app.add_flag("--subactive"); | |
| 1400 | + auto *opt2 = app.add_flag("--dummy"); | |
| 1401 | 1401 | sub1->needs(opt); |
| 1402 | 1402 | CHECK_THROWS_AS(sub1->needs((CLI::Option *)nullptr), CLI::OptionNotFound); |
| 1403 | 1403 | CHECK_THROWS_AS(sub1->needs((CLI::App *)nullptr), CLI::OptionNotFound); |
| ... | ... | @@ -1491,20 +1491,20 @@ TEST_CASE_METHOD(ManySubcommands, "SubcommandSilence", "[subcom]") { |
| 1491 | 1491 | |
| 1492 | 1492 | TEST_CASE_METHOD(TApp, "UnnamedSub", "[subcom]") { |
| 1493 | 1493 | double val{0.0}; |
| 1494 | - auto sub = app.add_subcommand("", "empty name"); | |
| 1495 | - auto opt = sub->add_option("-v,--value", val); | |
| 1494 | + auto *sub = app.add_subcommand("", "empty name"); | |
| 1495 | + auto *opt = sub->add_option("-v,--value", val); | |
| 1496 | 1496 | args = {"-v", "4.56"}; |
| 1497 | 1497 | |
| 1498 | 1498 | run(); |
| 1499 | 1499 | CHECK(4.56 == val); |
| 1500 | 1500 | // make sure unnamed sub options can be found from the main app |
| 1501 | - auto opt2 = app.get_option("-v"); | |
| 1501 | + auto *opt2 = app.get_option("-v"); | |
| 1502 | 1502 | CHECK(opt2 == opt); |
| 1503 | 1503 | |
| 1504 | 1504 | CHECK_THROWS_AS(app.get_option("--vvvv"), CLI::OptionNotFound); |
| 1505 | 1505 | // now test in the constant context |
| 1506 | 1506 | const auto &appC = app; |
| 1507 | - auto opt3 = appC.get_option("-v"); | |
| 1507 | + const auto *opt3 = appC.get_option("-v"); | |
| 1508 | 1508 | CHECK("--value" == opt3->get_name()); |
| 1509 | 1509 | CHECK_THROWS_AS(appC.get_option("--vvvv"), CLI::OptionNotFound); |
| 1510 | 1510 | } |
| ... | ... | @@ -1512,9 +1512,9 @@ TEST_CASE_METHOD(TApp, "UnnamedSub", "[subcom]") { |
| 1512 | 1512 | TEST_CASE_METHOD(TApp, "UnnamedSubMix", "[subcom]") { |
| 1513 | 1513 | double val{0.0}, val2{0.0}, val3{0.0}; |
| 1514 | 1514 | app.add_option("-t", val2); |
| 1515 | - auto sub1 = app.add_subcommand("", "empty name"); | |
| 1515 | + auto *sub1 = app.add_subcommand("", "empty name"); | |
| 1516 | 1516 | sub1->add_option("-v,--value", val); |
| 1517 | - auto sub2 = app.add_subcommand("", "empty name2"); | |
| 1517 | + auto *sub2 = app.add_subcommand("", "empty name2"); | |
| 1518 | 1518 | sub2->add_option("-m,--mix", val3); |
| 1519 | 1519 | args = {"-m", "4.56", "-t", "5.93", "-v", "-3"}; |
| 1520 | 1520 | |
| ... | ... | @@ -1528,7 +1528,7 @@ TEST_CASE_METHOD(TApp, "UnnamedSubMix", "[subcom]") { |
| 1528 | 1528 | TEST_CASE_METHOD(TApp, "UnnamedSubMixExtras", "[subcom]") { |
| 1529 | 1529 | double val{0.0}, val2{0.0}; |
| 1530 | 1530 | app.add_option("-t", val2); |
| 1531 | - auto sub = app.add_subcommand("", "empty name"); | |
| 1531 | + auto *sub = app.add_subcommand("", "empty name"); | |
| 1532 | 1532 | sub->add_option("-v,--value", val); |
| 1533 | 1533 | args = {"-m", "4.56", "-t", "5.93", "-v", "-3"}; |
| 1534 | 1534 | app.allow_extras(); |
| ... | ... | @@ -1542,7 +1542,7 @@ TEST_CASE_METHOD(TApp, "UnnamedSubMixExtras", "[subcom]") { |
| 1542 | 1542 | TEST_CASE_METHOD(TApp, "UnnamedSubNoExtras", "[subcom]") { |
| 1543 | 1543 | double val{0.0}, val2{0.0}; |
| 1544 | 1544 | app.add_option("-t", val2); |
| 1545 | - auto sub = app.add_subcommand(); | |
| 1545 | + auto *sub = app.add_subcommand(); | |
| 1546 | 1546 | sub->add_option("-v,--value", val); |
| 1547 | 1547 | args = {"-t", "5.93", "-v", "-3"}; |
| 1548 | 1548 | run(); |
| ... | ... | @@ -1554,7 +1554,7 @@ TEST_CASE_METHOD(TApp, "UnnamedSubNoExtras", "[subcom]") { |
| 1554 | 1554 | |
| 1555 | 1555 | TEST_CASE_METHOD(TApp, "SubcommandAlias", "[subcom]") { |
| 1556 | 1556 | double val{0.0}; |
| 1557 | - auto sub = app.add_subcommand("sub1"); | |
| 1557 | + auto *sub = app.add_subcommand("sub1"); | |
| 1558 | 1558 | sub->alias("sub2"); |
| 1559 | 1559 | sub->alias("sub3"); |
| 1560 | 1560 | sub->add_option("-v,--value", val); |
| ... | ... | @@ -1570,7 +1570,7 @@ TEST_CASE_METHOD(TApp, "SubcommandAlias", "[subcom]") { |
| 1570 | 1570 | run(); |
| 1571 | 1571 | CHECK(7 == val); |
| 1572 | 1572 | |
| 1573 | - auto &al = sub->get_aliases(); | |
| 1573 | + const auto &al = sub->get_aliases(); | |
| 1574 | 1574 | REQUIRE(2U <= al.size()); |
| 1575 | 1575 | |
| 1576 | 1576 | CHECK("sub2" == al[0]); |
| ... | ... | @@ -1582,7 +1582,7 @@ TEST_CASE_METHOD(TApp, "SubcommandAlias", "[subcom]") { |
| 1582 | 1582 | |
| 1583 | 1583 | TEST_CASE_METHOD(TApp, "SubcommandAliasIgnoreCaseUnderscore", "[subcom]") { |
| 1584 | 1584 | double val{0.0}; |
| 1585 | - auto sub = app.add_subcommand("sub1"); | |
| 1585 | + auto *sub = app.add_subcommand("sub1"); | |
| 1586 | 1586 | sub->alias("sub2"); |
| 1587 | 1587 | sub->alias("sub3"); |
| 1588 | 1588 | sub->ignore_case(); |
| ... | ... | @@ -1625,7 +1625,7 @@ TEST_CASE_METHOD(TApp, "SubcommandAliasIgnoreCaseUnderscore", "[subcom]") { |
| 1625 | 1625 | |
| 1626 | 1626 | TEST_CASE_METHOD(TApp, "OptionGroupAlias", "[subcom]") { |
| 1627 | 1627 | double val{0.0}; |
| 1628 | - auto sub = app.add_option_group("sub1"); | |
| 1628 | + auto *sub = app.add_option_group("sub1"); | |
| 1629 | 1629 | sub->alias("sub2"); |
| 1630 | 1630 | sub->alias("sub3"); |
| 1631 | 1631 | sub->add_option("-v,--value", val); |
| ... | ... | @@ -1647,7 +1647,7 @@ TEST_CASE_METHOD(TApp, "OptionGroupAlias", "[subcom]") { |
| 1647 | 1647 | |
| 1648 | 1648 | TEST_CASE_METHOD(TApp, "OptionGroupAliasWithSpaces", "[subcom]") { |
| 1649 | 1649 | double val{0.0}; |
| 1650 | - auto sub = app.add_option_group("sub1"); | |
| 1650 | + auto *sub = app.add_option_group("sub1"); | |
| 1651 | 1651 | sub->alias("sub2 bb"); |
| 1652 | 1652 | sub->alias("sub3/b"); |
| 1653 | 1653 | sub->add_option("-v,--value", val); |
| ... | ... | @@ -1668,7 +1668,7 @@ TEST_CASE_METHOD(TApp, "OptionGroupAliasWithSpaces", "[subcom]") { |
| 1668 | 1668 | } |
| 1669 | 1669 | |
| 1670 | 1670 | TEST_CASE_METHOD(TApp, "subcommand_help", "[subcom]") { |
| 1671 | - auto sub1 = app.add_subcommand("help")->silent(); | |
| 1671 | + auto *sub1 = app.add_subcommand("help")->silent(); | |
| 1672 | 1672 | bool flag{false}; |
| 1673 | 1673 | app.add_flag("--one", flag, "FLAGGER"); |
| 1674 | 1674 | sub1->parse_complete_callback([]() { throw CLI::CallForHelp(); }); |
| ... | ... | @@ -1685,8 +1685,8 @@ TEST_CASE_METHOD(TApp, "subcommand_help", "[subcom]") { |
| 1685 | 1685 | } |
| 1686 | 1686 | |
| 1687 | 1687 | TEST_CASE_METHOD(TApp, "AliasErrors", "[subcom]") { |
| 1688 | - auto sub1 = app.add_subcommand("sub1"); | |
| 1689 | - auto sub2 = app.add_subcommand("sub2"); | |
| 1688 | + auto *sub1 = app.add_subcommand("sub1"); | |
| 1689 | + auto *sub2 = app.add_subcommand("sub2"); | |
| 1690 | 1690 | |
| 1691 | 1691 | CHECK_THROWS_AS(sub2->alias("this is a not\n a valid alias"), CLI::IncorrectConstruction); |
| 1692 | 1692 | CHECK_NOTHROW(sub2->alias("-alias")); // this is allowed but would be unusable on command line parsers |
| ... | ... | @@ -1743,9 +1743,9 @@ TEST_CASE_METHOD(TApp, "ExistingSubcommandMatch", "[subcom]") { |
| 1743 | 1743 | } |
| 1744 | 1744 | |
| 1745 | 1745 | TEST_CASE_METHOD(TApp, "AliasErrorsInOptionGroup", "[subcom]") { |
| 1746 | - auto sub1 = app.add_subcommand("sub1"); | |
| 1747 | - auto g2 = app.add_option_group("g1"); | |
| 1748 | - auto sub2 = g2->add_subcommand("sub2"); | |
| 1746 | + auto *sub1 = app.add_subcommand("sub1"); | |
| 1747 | + auto *g2 = app.add_option_group("g1"); | |
| 1748 | + auto *sub2 = g2->add_subcommand("sub2"); | |
| 1749 | 1749 | |
| 1750 | 1750 | // cannot alias to an existing subcommand even if it is in an option group |
| 1751 | 1751 | CHECK_THROWS_AS(sub2->alias("sub1"), CLI::OptionAlreadyAdded); |
| ... | ... | @@ -1765,7 +1765,7 @@ TEST_CASE("SharedSubTests: SharedSubcommand", "[subcom]") { |
| 1765 | 1765 | CLI::App app1{"test program1"}; |
| 1766 | 1766 | |
| 1767 | 1767 | app1.add_option("-t", val2); |
| 1768 | - auto sub = app1.add_subcommand("", "empty name"); | |
| 1768 | + auto *sub = app1.add_subcommand("", "empty name"); | |
| 1769 | 1769 | sub->add_option("-v,--value", val); |
| 1770 | 1770 | sub->add_option("-g", val4); |
| 1771 | 1771 | CLI::App app2{"test program2"}; |
| ... | ... | @@ -1795,7 +1795,7 @@ TEST_CASE("SharedSubTests: SharedSubIndependent", "[subcom]") { |
| 1795 | 1795 | CLI::App_p app1 = std::make_shared<CLI::App>("test program1"); |
| 1796 | 1796 | app1->allow_extras(); |
| 1797 | 1797 | app1->add_option("-t", val2); |
| 1798 | - auto sub = app1->add_subcommand("", "empty name"); | |
| 1798 | + auto *sub = app1->add_subcommand("", "empty name"); | |
| 1799 | 1799 | sub->add_option("-v,--value", val); |
| 1800 | 1800 | sub->add_option("-g", val4); |
| 1801 | 1801 | |
| ... | ... | @@ -1823,7 +1823,7 @@ TEST_CASE("SharedSubTests: SharedSubIndependentReuse", "[subcom]") { |
| 1823 | 1823 | CLI::App_p app1 = std::make_shared<CLI::App>("test program1"); |
| 1824 | 1824 | app1->allow_extras(); |
| 1825 | 1825 | app1->add_option("-t", val2); |
| 1826 | - auto sub = app1->add_subcommand("", "empty name"); | |
| 1826 | + auto *sub = app1->add_subcommand("", "empty name"); | |
| 1827 | 1827 | sub->add_option("-v,--value", val); |
| 1828 | 1828 | sub->add_option("-g", val4); |
| 1829 | 1829 | |
| ... | ... | @@ -1884,14 +1884,14 @@ TEST_CASE_METHOD(ManySubcommands, "defaultEnabledSubcommand", "[subcom]") { |
| 1884 | 1884 | sub2->enabled_by_default(); |
| 1885 | 1885 | run(); |
| 1886 | 1886 | auto rem = app.remaining(); |
| 1887 | - CHECK(0u == rem.size()); | |
| 1887 | + CHECK(rem.empty()); | |
| 1888 | 1888 | CHECK(sub2->get_enabled_by_default()); |
| 1889 | 1889 | sub2->disabled(); |
| 1890 | 1890 | CHECK(sub2->get_disabled()); |
| 1891 | 1891 | run(); |
| 1892 | 1892 | // this should disable it again even though it was disabled |
| 1893 | 1893 | rem = app.remaining(); |
| 1894 | - CHECK(0u == rem.size()); | |
| 1894 | + CHECK(rem.empty()); | |
| 1895 | 1895 | CHECK(sub2->get_enabled_by_default()); |
| 1896 | 1896 | CHECK(!sub2->get_disabled()); |
| 1897 | 1897 | } |
| ... | ... | @@ -1960,7 +1960,7 @@ TEST_CASE_METHOD(TApp, "MultiFinalCallbackCounts", "[subcom]") { |
| 1960 | 1960 | TEST_CASE_METHOD(TApp, "SubcommandInOptionGroupCallbackCount", "[subcom]") { |
| 1961 | 1961 | |
| 1962 | 1962 | int subcount{0}; |
| 1963 | - auto group1 = app.add_option_group("FirstGroup"); | |
| 1963 | + auto *group1 = app.add_option_group("FirstGroup"); | |
| 1964 | 1964 | |
| 1965 | 1965 | group1->add_subcommand("g1c1")->callback([&subcount]() { ++subcount; }); |
| 1966 | 1966 | ... | ... |
tests/TransformTest.cpp
| ... | ... | @@ -6,6 +6,8 @@ |
| 6 | 6 | |
| 7 | 7 | #include "app_helper.hpp" |
| 8 | 8 | |
| 9 | +#include <cmath> | |
| 10 | + | |
| 9 | 11 | #include <array> |
| 10 | 12 | #include <chrono> |
| 11 | 13 | #include <cstdint> |
| ... | ... | @@ -22,7 +24,7 @@ |
| 22 | 24 | |
| 23 | 25 | TEST_CASE_METHOD(TApp, "SimpleTransform", "[transform]") { |
| 24 | 26 | int value{0}; |
| 25 | - auto opt = app.add_option("-s", value)->transform(CLI::Transformer({{"one", std::string("1")}})); | |
| 27 | + auto *opt = app.add_option("-s", value)->transform(CLI::Transformer({{"one", std::string("1")}})); | |
| 26 | 28 | args = {"-s", "one"}; |
| 27 | 29 | run(); |
| 28 | 30 | CHECK(app.count("-s") == 1u); |
| ... | ... | @@ -32,7 +34,7 @@ TEST_CASE_METHOD(TApp, "SimpleTransform", "[transform]") { |
| 32 | 34 | |
| 33 | 35 | TEST_CASE_METHOD(TApp, "SimpleTransformInitList", "[transform]") { |
| 34 | 36 | int value{0}; |
| 35 | - auto opt = app.add_option("-s", value)->transform(CLI::Transformer({{"one", "1"}})); | |
| 37 | + auto *opt = app.add_option("-s", value)->transform(CLI::Transformer({{"one", "1"}})); | |
| 36 | 38 | args = {"-s", "one"}; |
| 37 | 39 | run(); |
| 38 | 40 | CHECK(app.count("-s") == 1u); |
| ... | ... | @@ -42,7 +44,7 @@ TEST_CASE_METHOD(TApp, "SimpleTransformInitList", "[transform]") { |
| 42 | 44 | |
| 43 | 45 | TEST_CASE_METHOD(TApp, "SimpleNumericalTransform", "[transform]") { |
| 44 | 46 | int value{0}; |
| 45 | - auto opt = app.add_option("-s", value)->transform(CLI::Transformer(CLI::TransformPairs<int>{{"one", 1}})); | |
| 47 | + auto *opt = app.add_option("-s", value)->transform(CLI::Transformer(CLI::TransformPairs<int>{{"one", 1}})); | |
| 46 | 48 | args = {"-s", "one"}; |
| 47 | 49 | run(); |
| 48 | 50 | CHECK(app.count("-s") == 1u); |
| ... | ... | @@ -53,9 +55,9 @@ TEST_CASE_METHOD(TApp, "SimpleNumericalTransform", "[transform]") { |
| 53 | 55 | TEST_CASE_METHOD(TApp, "EnumTransform", "[transform]") { |
| 54 | 56 | enum class test_cli : std::int16_t { val1 = 3, val2 = 4, val3 = 17 }; |
| 55 | 57 | test_cli value{test_cli::val2}; |
| 56 | - auto opt = app.add_option("-s", value) | |
| 57 | - ->transform(CLI::Transformer(CLI::TransformPairs<test_cli>{ | |
| 58 | - {"val1", test_cli::val1}, {"val2", test_cli::val2}, {"val3", test_cli::val3}})); | |
| 58 | + auto *opt = app.add_option("-s", value) | |
| 59 | + ->transform(CLI::Transformer(CLI::TransformPairs<test_cli>{ | |
| 60 | + {"val1", test_cli::val1}, {"val2", test_cli::val2}, {"val3", test_cli::val3}})); | |
| 59 | 61 | args = {"-s", "val1"}; |
| 60 | 62 | run(); |
| 61 | 63 | CHECK(app.count("-s") == 1u); |
| ... | ... | @@ -82,9 +84,9 @@ TEST_CASE_METHOD(TApp, "EnumTransform", "[transform]") { |
| 82 | 84 | TEST_CASE_METHOD(TApp, "EnumCheckedTransform", "[transform]") { |
| 83 | 85 | enum class test_cli : std::int16_t { val1 = 3, val2 = 4, val3 = 17 }; |
| 84 | 86 | test_cli value{test_cli::val1}; |
| 85 | - auto opt = app.add_option("-s", value) | |
| 86 | - ->transform(CLI::CheckedTransformer(CLI::TransformPairs<test_cli>{ | |
| 87 | - {"val1", test_cli::val1}, {"val2", test_cli::val2}, {"val3", test_cli::val3}})); | |
| 87 | + auto *opt = app.add_option("-s", value) | |
| 88 | + ->transform(CLI::CheckedTransformer(CLI::TransformPairs<test_cli>{ | |
| 89 | + {"val1", test_cli::val1}, {"val2", test_cli::val2}, {"val3", test_cli::val3}})); | |
| 88 | 90 | args = {"-s", "val1"}; |
| 89 | 91 | run(); |
| 90 | 92 | CHECK(app.count("-s") == 1u); |
| ... | ... | @@ -149,7 +151,7 @@ TEST_CASE_METHOD(TApp, "EnumCheckedDefaultTransformCallback", "[transform]") { |
| 149 | 151 | |
| 150 | 152 | TEST_CASE_METHOD(TApp, "SimpleTransformFn", "[transform]") { |
| 151 | 153 | int value{0}; |
| 152 | - auto opt = app.add_option("-s", value)->transform(CLI::Transformer({{"one", "1"}}, CLI::ignore_case)); | |
| 154 | + auto *opt = app.add_option("-s", value)->transform(CLI::Transformer({{"one", "1"}}, CLI::ignore_case)); | |
| 153 | 155 | args = {"-s", "ONE"}; |
| 154 | 156 | run(); |
| 155 | 157 | CHECK(app.count("-s") == 1u); |
| ... | ... | @@ -172,7 +174,7 @@ TEST_CASE_METHOD(TApp, "StringViewTransformFn", "[transform]") { |
| 172 | 174 | |
| 173 | 175 | TEST_CASE_METHOD(TApp, "SimpleNumericalTransformFn", "[transform]") { |
| 174 | 176 | int value{0}; |
| 175 | - auto opt = | |
| 177 | + auto *opt = | |
| 176 | 178 | app.add_option("-s", value) |
| 177 | 179 | ->transform(CLI::Transformer(std::vector<std::pair<std::string, int>>{{"one", 1}}, CLI::ignore_case)); |
| 178 | 180 | args = {"-s", "ONe"}; |
| ... | ... | @@ -185,7 +187,7 @@ TEST_CASE_METHOD(TApp, "SimpleNumericalTransformFn", "[transform]") { |
| 185 | 187 | TEST_CASE_METHOD(TApp, "SimpleNumericalTransformFnVector", "[transform]") { |
| 186 | 188 | std::vector<std::pair<std::string, int>> conversions{{"one", 1}, {"two", 2}}; |
| 187 | 189 | int value{0}; |
| 188 | - auto opt = app.add_option("-s", value)->transform(CLI::Transformer(conversions, CLI::ignore_case)); | |
| 190 | + auto *opt = app.add_option("-s", value)->transform(CLI::Transformer(conversions, CLI::ignore_case)); | |
| 189 | 191 | args = {"-s", "ONe"}; |
| 190 | 192 | run(); |
| 191 | 193 | CHECK(app.count("-s") == 1u); |
| ... | ... | @@ -199,7 +201,7 @@ TEST_CASE_METHOD(TApp, "SimpleNumericalTransformFnArray", "[transform]") { |
| 199 | 201 | conversions[1] = std::make_pair(std::string("two"), 2); |
| 200 | 202 | |
| 201 | 203 | int value{0}; |
| 202 | - auto opt = app.add_option("-s", value)->transform(CLI::Transformer(conversions, CLI::ignore_case)); | |
| 204 | + auto *opt = app.add_option("-s", value)->transform(CLI::Transformer(conversions, CLI::ignore_case)); | |
| 203 | 205 | args = {"-s", "ONe"}; |
| 204 | 206 | run(); |
| 205 | 207 | CHECK(app.count("-s") == 1u); |
| ... | ... | @@ -215,7 +217,7 @@ TEST_CASE_METHOD(TApp, "SimpleNumericalTransformFnconstexprArray", "[transform]" |
| 215 | 217 | constexpr std::array<std::pair<const char *, int>, 2> conversions_c{{p1, p2}}; |
| 216 | 218 | |
| 217 | 219 | int value{0}; |
| 218 | - auto opt = app.add_option("-s", value)->transform(CLI::Transformer(&conversions_c, CLI::ignore_case)); | |
| 220 | + auto *opt = app.add_option("-s", value)->transform(CLI::Transformer(&conversions_c, CLI::ignore_case)); | |
| 219 | 221 | args = {"-s", "ONe"}; |
| 220 | 222 | run(); |
| 221 | 223 | CHECK(app.count("-s") == 1u); |
| ... | ... | @@ -233,12 +235,12 @@ TEST_CASE_METHOD(TApp, "SimpleNumericalTransformFnconstexprArray", "[transform]" |
| 233 | 235 | TEST_CASE_METHOD(TApp, "EnumTransformFn", "[transform]") { |
| 234 | 236 | enum class test_cli : std::int16_t { val1 = 3, val2 = 4, val3 = 17 }; |
| 235 | 237 | test_cli value{test_cli::val2}; |
| 236 | - auto opt = app.add_option("-s", value) | |
| 237 | - ->transform(CLI::Transformer(CLI::TransformPairs<test_cli>{{"val1", test_cli::val1}, | |
| 238 | - {"val2", test_cli::val2}, | |
| 239 | - {"val3", test_cli::val3}}, | |
| 240 | - CLI::ignore_case, | |
| 241 | - CLI::ignore_underscore)); | |
| 238 | + auto *opt = app.add_option("-s", value) | |
| 239 | + ->transform(CLI::Transformer(CLI::TransformPairs<test_cli>{{"val1", test_cli::val1}, | |
| 240 | + {"val2", test_cli::val2}, | |
| 241 | + {"val3", test_cli::val3}}, | |
| 242 | + CLI::ignore_case, | |
| 243 | + CLI::ignore_underscore)); | |
| 242 | 244 | args = {"-s", "val_1"}; |
| 243 | 245 | run(); |
| 244 | 246 | CHECK(app.count("-s") == 1u); |
| ... | ... | @@ -261,7 +263,7 @@ TEST_CASE_METHOD(TApp, "EnumTransformFnMap", "[transform]") { |
| 261 | 263 | enum class test_cli : std::int16_t { val1 = 3, val2 = 4, val3 = 17 }; |
| 262 | 264 | std::map<std::string, test_cli> map{{"val1", test_cli::val1}, {"val2", test_cli::val2}, {"val3", test_cli::val3}}; |
| 263 | 265 | test_cli value{test_cli::val3}; |
| 264 | - auto opt = app.add_option("-s", value)->transform(CLI::Transformer(map, CLI::ignore_case, CLI::ignore_underscore)); | |
| 266 | + auto *opt = app.add_option("-s", value)->transform(CLI::Transformer(map, CLI::ignore_case, CLI::ignore_underscore)); | |
| 265 | 267 | args = {"-s", "val_1"}; |
| 266 | 268 | run(); |
| 267 | 269 | CHECK(app.count("-s") == 1u); |
| ... | ... | @@ -284,7 +286,8 @@ TEST_CASE_METHOD(TApp, "EnumTransformFnPtrMap", "[transform]") { |
| 284 | 286 | enum class test_cli : std::int16_t { val1 = 3, val2 = 4, val3 = 17, val4 = 37 }; |
| 285 | 287 | std::map<std::string, test_cli> map{{"val1", test_cli::val1}, {"val2", test_cli::val2}, {"val3", test_cli::val3}}; |
| 286 | 288 | test_cli value{test_cli::val2}; |
| 287 | - auto opt = app.add_option("-s", value)->transform(CLI::Transformer(&map, CLI::ignore_case, CLI::ignore_underscore)); | |
| 289 | + auto *opt = | |
| 290 | + app.add_option("-s", value)->transform(CLI::Transformer(&map, CLI::ignore_case, CLI::ignore_underscore)); | |
| 288 | 291 | args = {"-s", "val_1"}; |
| 289 | 292 | run(); |
| 290 | 293 | CHECK(app.count("-s") == 1u); |
| ... | ... | @@ -316,7 +319,7 @@ TEST_CASE_METHOD(TApp, "EnumTransformFnSharedPtrMap", "[transform]") { |
| 316 | 319 | mp["val3"] = test_cli::val3; |
| 317 | 320 | |
| 318 | 321 | test_cli value{test_cli::val2}; |
| 319 | - auto opt = app.add_option("-s", value)->transform(CLI::Transformer(map, CLI::ignore_case, CLI::ignore_underscore)); | |
| 322 | + auto *opt = app.add_option("-s", value)->transform(CLI::Transformer(map, CLI::ignore_case, CLI::ignore_underscore)); | |
| 320 | 323 | args = {"-s", "val_1"}; |
| 321 | 324 | run(); |
| 322 | 325 | CHECK(app.count("-s") == 1u); |
| ... | ... | @@ -343,7 +346,7 @@ TEST_CASE_METHOD(TApp, "EnumTransformFnSharedPtrMap", "[transform]") { |
| 343 | 346 | TEST_CASE_METHOD(TApp, "TransformCascade", "[transform]") { |
| 344 | 347 | |
| 345 | 348 | std::string output; |
| 346 | - auto opt = app.add_option("-s", output); | |
| 349 | + auto *opt = app.add_option("-s", output); | |
| 347 | 350 | opt->transform(CLI::Transformer({{"abc", "abcd"}, {"bbc", "bbcd"}, {"cbc", "cbcd"}}, CLI::ignore_case)); |
| 348 | 351 | opt->transform( |
| 349 | 352 | CLI::Transformer({{"ab", "abc"}, {"bc", "bbc"}, {"cb", "cbc"}}, CLI::ignore_case, CLI::ignore_underscore)); |
| ... | ... | @@ -370,7 +373,7 @@ TEST_CASE_METHOD(TApp, "TransformCascade", "[transform]") { |
| 370 | 373 | TEST_CASE_METHOD(TApp, "TransformCascadeDeactivate", "[transform]") { |
| 371 | 374 | |
| 372 | 375 | std::string output; |
| 373 | - auto opt = app.add_option("-s", output); | |
| 376 | + auto *opt = app.add_option("-s", output); | |
| 374 | 377 | opt->transform( |
| 375 | 378 | CLI::Transformer({{"abc", "abcd"}, {"bbc", "bbcd"}, {"cbc", "cbcd"}}, CLI::ignore_case).name("tform1")); |
| 376 | 379 | opt->transform( |
| ... | ... | @@ -390,7 +393,7 @@ TEST_CASE_METHOD(TApp, "TransformCascadeDeactivate", "[transform]") { |
| 390 | 393 | args = {"-s", "C_B"}; |
| 391 | 394 | CHECK_THROWS_AS(run(), CLI::ValidationError); |
| 392 | 395 | |
| 393 | - auto validator = opt->get_validator("tform2"); | |
| 396 | + auto *validator = opt->get_validator("tform2"); | |
| 394 | 397 | CHECK(!validator->get_active()); |
| 395 | 398 | CHECK("tform2" == validator->get_name()); |
| 396 | 399 | validator->active(); |
| ... | ... | @@ -475,28 +478,28 @@ TEST_CASE_METHOD(TApp, "IntTransformNonMerge", "[transform]") { |
| 475 | 478 | CHECK(help.find("15->5") != std::string::npos); |
| 476 | 479 | CHECK(help.find("25->5") != std::string::npos); |
| 477 | 480 | |
| 478 | - auto validator = app.get_option("-s")->get_validator(); | |
| 481 | + auto *validator = app.get_option("-s")->get_validator(); | |
| 479 | 482 | help = validator->get_description(); |
| 480 | 483 | CHECK(help.find("15->5") != std::string::npos); |
| 481 | 484 | CHECK(help.find("25->5") != std::string::npos); |
| 482 | 485 | |
| 483 | - auto validator2 = app.get_option("-s")->get_validator("merge"); | |
| 486 | + auto *validator2 = app.get_option("-s")->get_validator("merge"); | |
| 484 | 487 | CHECK(validator == validator2); |
| 485 | 488 | } |
| 486 | 489 | |
| 487 | 490 | TEST_CASE_METHOD(TApp, "IntTransformMergeWithCustomValidator", "[transform]") { |
| 488 | 491 | std::string value; |
| 489 | - auto opt = app.add_option("-s", value) | |
| 490 | - ->transform(CLI::Transformer(std::map<int, int>{{15, 5}, {18, 6}, {21, 7}}) | | |
| 491 | - CLI::Validator( | |
| 492 | - [](std::string &element) { | |
| 493 | - if(element == "frog") { | |
| 494 | - element = "hops"; | |
| 495 | - } | |
| 496 | - return std::string{}; | |
| 497 | - }, | |
| 498 | - std::string{}), | |
| 499 | - "check"); | |
| 492 | + auto *opt = app.add_option("-s", value) | |
| 493 | + ->transform(CLI::Transformer(std::map<int, int>{{15, 5}, {18, 6}, {21, 7}}) | | |
| 494 | + CLI::Validator( | |
| 495 | + [](std::string &element) { | |
| 496 | + if(element == "frog") { | |
| 497 | + element = "hops"; | |
| 498 | + } | |
| 499 | + return std::string{}; | |
| 500 | + }, | |
| 501 | + std::string{}), | |
| 502 | + "check"); | |
| 500 | 503 | args = {"-s", "15"}; |
| 501 | 504 | run(); |
| 502 | 505 | CHECK("5" == value); |
| ... | ... | @@ -518,7 +521,7 @@ TEST_CASE_METHOD(TApp, "IntTransformMergeWithCustomValidator", "[transform]") { |
| 518 | 521 | CHECK(help.find("15->5") != std::string::npos); |
| 519 | 522 | CHECK(help.find("OR") == std::string::npos); |
| 520 | 523 | |
| 521 | - auto validator = opt->get_validator("check"); | |
| 524 | + auto *validator = opt->get_validator("check"); | |
| 522 | 525 | CHECK("check" == validator->get_name()); |
| 523 | 526 | validator->active(false); |
| 524 | 527 | help = app.help(); |
| ... | ... | @@ -526,7 +529,7 @@ TEST_CASE_METHOD(TApp, "IntTransformMergeWithCustomValidator", "[transform]") { |
| 526 | 529 | } |
| 527 | 530 | |
| 528 | 531 | TEST_CASE_METHOD(TApp, "BoundTests", "[transform]") { |
| 529 | - double value; | |
| 532 | + double value = NAN; | |
| 530 | 533 | app.add_option("-s", value)->transform(CLI::Bound(3.4, 5.9)); |
| 531 | 534 | args = {"-s", "15"}; |
| 532 | 535 | run(); |
| ... | ... | @@ -636,9 +639,8 @@ TEST_CASE_METHOD(TApp, "NumberWithUnitMandatoryUnit", "[transform]") { |
| 636 | 639 | |
| 637 | 640 | int value{0}; |
| 638 | 641 | app.add_option("-n", value) |
| 639 | - ->transform(CLI::AsNumberWithUnit(mapping, | |
| 640 | - CLI::AsNumberWithUnit::Options(CLI::AsNumberWithUnit::UNIT_REQUIRED | | |
| 641 | - CLI::AsNumberWithUnit::CASE_SENSITIVE))); | |
| 642 | + ->transform(CLI::AsNumberWithUnit( | |
| 643 | + mapping, CLI::AsNumberWithUnit::UNIT_REQUIRED | CLI::AsNumberWithUnit::CASE_SENSITIVE)); | |
| 642 | 644 | |
| 643 | 645 | args = {"-n", "42a"}; |
| 644 | 646 | run(); |
| ... | ... | @@ -657,9 +659,8 @@ TEST_CASE_METHOD(TApp, "NumberWithUnitMandatoryUnit2", "[transform]") { |
| 657 | 659 | |
| 658 | 660 | int value{0}; |
| 659 | 661 | app.add_option("-n", value) |
| 660 | - ->transform(CLI::AsNumberWithUnit(mapping, | |
| 661 | - CLI::AsNumberWithUnit::Options(CLI::AsNumberWithUnit::UNIT_REQUIRED | | |
| 662 | - CLI::AsNumberWithUnit::CASE_INSENSITIVE))); | |
| 662 | + ->transform(CLI::AsNumberWithUnit( | |
| 663 | + mapping, CLI::AsNumberWithUnit::UNIT_REQUIRED | CLI::AsNumberWithUnit::CASE_INSENSITIVE)); | |
| 663 | 664 | |
| 664 | 665 | args = {"-n", "42A"}; |
| 665 | 666 | run(); |
| ... | ... | @@ -708,7 +709,7 @@ TEST_CASE_METHOD(TApp, "NumberWithUnitBadInput", "[transform]") { |
| 708 | 709 | TEST_CASE_METHOD(TApp, "NumberWithUnitIntOverflow", "[transform]") { |
| 709 | 710 | std::map<std::string, int> mapping{{"a", 1000000}, {"b", 100}, {"c", 101}}; |
| 710 | 711 | |
| 711 | - std::int32_t value; | |
| 712 | + std::int32_t value = 0; | |
| 712 | 713 | app.add_option("-n", value)->transform(CLI::AsNumberWithUnit(mapping)); |
| 713 | 714 | |
| 714 | 715 | args = {"-n", "1000 a"}; | ... | ... |
tests/app_helper.hpp
| ... | ... | @@ -46,8 +46,8 @@ class TempFile { |
| 46 | 46 | std::remove(_name.c_str()); // Doesn't matter if returns 0 or not |
| 47 | 47 | } |
| 48 | 48 | |
| 49 | - operator const std::string &() const { return _name; } | |
| 50 | - const char *c_str() const { return _name.c_str(); } | |
| 49 | + operator const std::string &() const { return _name; } // NOLINT(google-explicit-constructor) | |
| 50 | + CLI11_NODISCARD const char *c_str() const { return _name.c_str(); } | |
| 51 | 51 | }; |
| 52 | 52 | |
| 53 | 53 | inline void put_env(std::string name, std::string value) { | ... | ... |