1
0
mirror of https://github.com/CLIUtils/CLI11.git synced 2025-04-29 20:23:55 +00:00

76 Commits

Author SHA1 Message Date
Guillem Blanco
b0f63a4442
Fix spelling in Error.hpp (#1129)
Co-authored-by: Philip Top <phlptp@gmail.com>
2025-03-03 05:39:43 -08:00
Philip Top
74c86d4889
update copyright dates to 2025 (#1112) 2025-01-03 08:35:31 -08:00
Josh Soref
ef50bb35c3
Spelling (#1101)
This PR corrects misspellings identified by the [check-spelling
action](https://github.com/marketplace/actions/check-spelling) (which is
an evolution of the script I used ages ago when I first made a PR
here...).

The misspellings have been reported at
https://github.com/jsoref/CLI11/actions/runs/12194174338#summary-34017587518

The action reports that the changes in this PR would make it happy:
https://github.com/jsoref/CLI11/actions/runs/12194174680#summary-34017588281

---------

Signed-off-by: Josh Soref <2119212+jsoref@users.noreply.github.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2024-12-22 14:03:24 -08:00
Philip Top
f7600953d4
add a round trip test to the fuzzer (#1060)
This is the next phase of the fuzzer. It runs a round trip and makes
sure that the config files generated by the app will load into the same
results, to test full round trip on the config files.

Issues fixed
- fix a bug in the string escape code caught by initial round trip tests
- resolve inconsistencies in handling of {} for empty vector indication
between config and cli parsing

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2024-09-23 06:13:47 -07:00
Ethan Sifferman
8bf340d10b
fix: improved clarity in RequiredError (#1029)
Hello. Thank you for this tool.

I found a few small typos in the RequiredError class.

This is an error message I received:

```
Requires at most 2 options be used and 3were given from [filename,--get-size,--get-size2]
```
This PR changes the error message to
```
Requires at most 2 options be used but 3 were given from [filename,--get-size,--get-size2]
```

Happy to make changes as needed!

## Source

```cpp
    std::string filename;
    bool get_size = false;

    CLI::App app{"Program to read a file specified as command-line argument"};

    app.add_option("filename", filename, "File to read")->required();
    app.add_flag("--get-size", get_size, "Print the size of the file");
    app.add_flag("--get-size2", get_size, "Print the size of the file2");

    app.require_option(1, 2); // Enforce only one flag can be input

    CLI11_PARSE(app, argc, argv);
```

## Further Idea

Also, another idea I had was to remove required options from this error
message. In this example, "filename" is required, so a better error
message would be
```
Requires at most 1 options be used but 2 were given from [--get-size,--get-size2]
```
I'm happy to look into this if you feel it would be valuable
2024-04-07 00:17:35 -04:00
gostefan
2fa609ad55
Add IWYU pragmas (#1008)
Added include-what-you-use pragmas to:
* let IWYU point users to the main include file CLI/CLI.hpp
* tell IWYU that CLI/CLI.hpp is the main exporting header.

This should fix #816

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Philip Top <phlptp@gmail.com>
2024-03-19 17:49:34 -07:00
Philip Top
9dfeefe2ba
update copyright date to 2024 (#971)
update copyright dates
2024-01-06 08:08:31 -08:00
Philip Top
0f5bf21e91
add some reduction methods to the options on the fuzz tests (#930)
This adds a round trip test for config file generation to the fuzzer. 

(the next step after this PR will be a fuzzer that verifies that the
round trip actually matches the results.
This change ended up requiring quite a few minor changes to fix the
ambiguities between the config file generation and config file reader.

1). There was a number of potential conflicts between positional names
and regular option names that could be triggered in config files, this
required a number of additional checks on the positional naming to
ensure no conflicts.
2). flag options with disable flag override can produce output results
that are not valid by themselves, resolving this required flag input to
be able to handle an array and output the original value set of results.
3). strings with non-printable characters could cause all sorts of chaos
in the config files. This was resolved by generating a binary string
conversion format and handling multiline comments and characters, and
handling escaped characters. Note; I think a better solution is to move
to fully supporting string formatting and escaping along with the binary
strings from TOML now that TOML 1.0 is finalized. That will not be this
PR though, maybe the next one.
4). Lot of ambiguities and edge cases in the string splitter, this was
reworked
5). handling of comments was not done well, especially comment characters in the
name of the option which is allowed.
6). non printable characters in the option naming. This would be weird
in practice but it also cause some big holes in the config file
generation, so the restricted character set for option naming was
expanded. (don't allow spaces or control characters).

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2023-12-18 05:21:32 -08:00
Philip Top
985a19f386
fix some doc and error strings (#899)
Update some doc strings and error output for clarity

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2023-06-29 08:29:32 -07:00
Philip Top
39a5f1981e
chore: update copyright year to 2023 (#825) 2023-01-03 17:29:37 -05:00
Matt McCormick
c57000e582
fix: add missing Macros.hpp include to Error.hpp (#755)
* Add missing Macros.hpp include to Error.hpp

To address:

```
In file included from /ITKWebAssemblyInterface/include/itkPipeline.h:21:
In file included from /ITKWebAssemblyInterface-build/_deps/cli11-src/include/CLI/App.hpp:25:
In file included from /ITKWebAssemblyInterface-build/_deps/cli11-src/include/CLI/ConfigFwd.hpp:17:
/ITKWebAssemblyInterface-build/_deps/cli11-src/include/CLI/Error.hpp:75:5: error: unknown type name 'CLI11_NODISCARD'
    CLI11_NODISCARD int get_exit_code() const { return actual_exit_code; }
    ^
```

* style: pre-commit.ci fixes

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2022-07-05 00:10:54 -04:00
Henry Schreiner
c781998273
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>
2022-06-26 14:53:01 -04:00
Philip Top
4cae08686d
docs: update copyright dates to 2022 (#717) 2022-03-26 21:54:49 -04:00
Philip Top
815553211b
fix and test some reported issues (#661) 2021-11-01 23:12:55 -04:00
Henry Schreiner
b4f6be31c1
chore: codacity (#621)
* docs: fix some Codacity recommendations

* chore: update copyright year

* style: more codacity fixes

* style: fix issues reported by Codacity
2021-07-16 17:41:46 -04:00
Henry Schreiner
f862849488
refactor: new version of MakeSingleFiles (#546)
* refactor: new version of MakeSingleFiles

* fix: use CMake and set version
2021-01-04 17:47:06 -05:00
Ryan Curtin
26555f9ea2
Grammar fix. (#510) 2020-09-09 14:08:41 -04:00
Sam Hocevar
2337bbf35d
Fix internal header include paths. (#475)
* Fix internal header include paths.

The extra leading "CLI/" part of include directives prevents the inclusion
of CLI.hpp from a relative directory without an extra -I or /I compiler
directive.

* Fix single header generation script.

Files included with "" should be relative to the header file location first.
2020-06-14 11:32:29 -04:00
Philip Top
41a9c294d0
Version add (#452)
* Add a dedicated version option to CLI11 to facilitate use of version flags, similar to help flags

* add some test for the version flag

* update errors and formatting

* clear up gcc 4.8 warnings

* add a few more tests

* fix compiler error

* fix a few comments, and change default version flag to only use "--version"

* remove `version` calls and tests

* formatting and add `std::string version()`  back in.
2020-05-24 23:18:44 -04:00
Christoph Bachhuber
d8a5bdc294
Add and fix cpplint whitespace/comments (#434)
* Add whitespace/comments check

* Adapt spacing in clang-format

* Fix cpplint whitespace/comments issues

* Grammar

* Do not use clang-format for comment spacing

* Fix with clang-format pre-commit hook
2020-03-06 00:04:59 -05:00
Josh Soref
51a0efcbbc
Spelling (#429)
* spelling: argument

* spelling: conflicts

* spelling: correctly

* spelling: default

* spelling: description

* spelling: empty

* spelling: enum

* spelling: javascript

* spelling: modifying

* spelling: nonexistent

* spelling: plumbum

* spelling: programmatically

* spelling: received

* spelling: replaced

* spelling: required

* spelling: sanitizers

* spelling: semicolon

* spelling: source

* spelling: subcommands

* spelling: successful
2020-02-12 00:41:58 -05:00
Christoph Bachhuber
34bfa38691
Add copyright and copyright check (#424)
* Add copyright check

* Remove old license message

* Implement suggestions from code review
2020-02-10 14:28:47 -05:00
Christoph Bachhuber
88b0bc4d95 Add include_what_you_use to cpplint checks (#414)
* Add build/include_what_you_use to cpplint checks

* Fix all cpplint build/include_what_you_use issues
2020-01-26 14:01:54 -06:00
Christoph Bachhuber
efbdd604af Refactor clang-tidy (#389)
* Make CI fail with readability-container-size-empty flag

* Make CI fail with cppcoreguidelines-owning-memory flag

* Add all google checks, exclude specific ones

* Apply clang-tidy fixes

* Make timer constructors explicit

* Add check for unscoped namespaces

* Replace unscoped namespace by using-declaration

* Replace unscoped namespace by using-declaration
2020-01-08 17:32:30 -05:00
Henry Schreiner
d5cd986046 Rename size_t -> std::size_t 2019-12-31 10:35:24 -05:00
Philip Top
418b7175f5 Type size refactor (#325)
* add expanded type_size specification

* add some more checks for type_size_max

* continued work on getting type sizes more flexible

* make some more tweaks to option to split up validate and reduce sections

* git rid of exceptions on the type_size functions exceptions,  allow any number to be entered for the min and max and don't make a distinction between flags and other types.

* add expected count

* add the allow extra args flag in an option

* start working in allow_extra_args

* write some stuff in the book,  and continue working on the failing test cases

* fix a few more of the helpers tests

* a few more test cases running

* all tests pass, fixing calls in ini files

* get vector<pair> working and all tests passing

* change callback to use reference to remove allocation and copy operation

* add support and test for vector<vector<X>>

* change Validators_ to validators_ for consistency

* fix linux warnings and errors by reording some templates and adding some typename keywords

* add support for std::vector<X> as the cross conversion type so optional<std::vector<X>> is supported using the full template of add_option.

* a few more test cases to take care of some coverage gaps

* add missing parenthesis

* add some more tests for coverage gaps

* add test for flag like option

* add transform test for `as<X>` function and make it pass through the defaults

* add a few more tests and have vector default string interpreted correctly.

* add test for defaulted integer,  and route default string for defaulted value which would otherwise be empty

* some code cleanup and comments and few more test coverage gap tests

* add more tests and fix a few bugs on the type size and different code paths

* remove path in results by fixing the clear of options so they go back to parsing state.

* get coverage back to 100%

* clang_tidy, and codacy fixes

* reorder the lexical_conversion definitions

* update some formatting

* update whitespace on book chapter
2019-11-10 05:36:16 +10:30
Philip Top
06ab2d0fbd Footer callback (#309)
fix incorrect parenthesis

update some clang-tidy fixes mainly else after return but a few conversions from into to bool

add extra newline before footer

add an extra field to the extra Error

add a footer callback for help operations
2019-08-18 19:51:14 -04:00
Philip Top
0631189b4d Option groups (#227)
* change the move function to _move_option and add an additional test

add a validation check on min options to make sure it is even possible to succeed.

add some additional tests to cover code paths and potential errors.

add a number of additional tests and checks and fix some issues with the add function in option_groups

clean up example and help formatting

add option_groups example to play with

move create_option_group to a member function using a dummy template

add some optionGroup tests

add min and max options calls and an associated Error call

* add ranges example,  add excludes to app for options and subcommands.

* add some tests on ranges, and some subcommand tests with exclusion

* add tests in optionGroups for some invalid inputs

* add required option to subcommands and option_groups

* add disabled flag

* add disable option to subcommands and some more tests

* start work on ReadMe modifications

* update the readme with descriptions of function and methods added for option_groups

* clear up gcc 4.7 warnings

* some update to the Readme and a few more warnings fixed

* Minor readme touchup
2019-03-01 17:43:08 +01:00
Philip Top
ed5cd89636 remove template for operator[] and adjust some tests
add some comments in readME about performance

move operator[] to return const Option *

Apply suggestions from code review

Co-Authored-By: phlptp <top1@llnl.gov>

update readme and add some IniTests and fix a bug from the tests

add_flag_callback

add a few tests to capture the different paths

fix incorrectly updated CMAKE file, and add some subcommand test for option finding

add disable_flag_override and work out some kinks in the find option functions

add some more tests and fix a few bugs in as<> function for options

Allow general flag types and default values, add shortcut notation for retrieving values
2019-02-23 07:40:41 +01:00
Philip Top
663d93c792 Clear up Wshadow warnings from gcc 4.9 (#191)
* Clear up Wshadow warnings from gcc 4.9.  Most of these were local variable names with the same name as a member function.
Also a few spelling fixes and adding some std::move around some of the arguments when appropriate.

* Touchup
2019-01-13 09:12:48 +01:00
Henry Fredrick Schreiner
9b54b6e0fe Undef error macros at end of file 2018-05-18 10:45:30 +02:00
Henry Fredrick Schreiner
d46c2c5727 Adding Config class 2018-05-09 16:08:32 +02:00
Henry Fredrick Schreiner
952f2913e3 First attempt at formatter (app and option)
in progress: formatters

Getting closer

Working on apps

One test actually runs

All builds, added filter functions

Reverting a few behavours as needed

Repairs

All tests pass

Fixing error with adding help flag

Labels are simpler mappings, normalized setters

Adding help_all

Adding a few more tests

One more line tested

Adding one more check

Adding to readme

Simplify naming

Adding default constructors

Fixing spacing issues with subcommand all printout

Adding a couple of tests
2018-04-30 08:17:31 -04:00
Henry Fredrick Schreiner
bd890e24a1 A few more explicit constructors 2018-04-13 14:15:09 +02:00
Henry Schreiner
b23275358a
Adding nicer header with LICENSE to single file version (#107)
* Adding nicer header with LICENSE to single file version

* Adding badges

* Clean up sh files

* Adding explicit in a few places

* More fixes from codacy
2018-04-13 14:07:32 +02:00
Henry Fredrick Schreiner
f059528559 Support for multi-size MultiOptionPolicies 2018-04-04 20:31:52 +02:00
Henry Fredrick Schreiner
447bda047f Adding size instead of expected + unchangable 2018-04-04 20:31:52 +02:00
Lucas Czech
378eb3406c Fix space in help output. 2018-01-07 17:26:53 +01:00
Henry Fredrick Schreiner
4dac11c025 Finishing addition of ->configurable() 2017-11-28 21:28:37 -05:00
Henry Fredrick Schreiner
c1fb53f00d Moving error messages definitions to Error.h 2017-11-28 21:28:37 -05:00
Henry Fredrick Schreiner
b010775051 Fix ArgumentMismatch missing public (makes it hard to catch) 2017-11-27 17:24:08 -05:00
Henry Fredrick Schreiner
fc69345f2f Improve one more message 2017-11-26 22:40:40 -05:00
Henry Fredrick Schreiner
133c7d5075 Allow suggestions for number of args 2017-11-26 15:11:48 -05:00
Henry Fredrick Schreiner
3e651e3b7e Moved more string processing to Error 2017-11-26 15:11:48 -05:00
Henry Fredrick Schreiner
f6c9ce6109 Moving code to Error, better ArgumentMismatch throwing 2017-11-26 15:11:48 -05:00
Henry Fredrick Schreiner
4d5bff2393 Adding ArgumentMismatch, changable improvement 2017-11-26 15:11:48 -05:00
Henry Fredrick Schreiner
c6fd8f4d83 A few warning fixes 2017-11-22 22:41:14 -05:00
Henry Fredrick Schreiner
a958ffece2 Dropping name from simple print, better seperation for Errors
Some error codes are renamed
2017-11-22 22:41:14 -05:00
Henry Fredrick Schreiner
02548a64d8 Adding the ability to set custom failure messages 2017-11-22 13:45:18 -05:00
Henry Fredrick Schreiner
0395467d48 Making RuntimeError a ParseError 2017-11-20 12:31:14 -05:00