1407 Commits

Author SHA1 Message Date
pre-commit-ci[bot]
6e9b07734c chore(deps): pre-commit.ci autoupdate (#1193)
<!--pre-commit.ci start-->
updates:
- [github.com/pre-commit/pre-commit-hooks: v5.0.0 →
v6.0.0](https://github.com/pre-commit/pre-commit-hooks/compare/v5.0.0...v6.0.0)
<!--pre-commit.ci end-->

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2025-08-12 05:15:12 -07:00
Philip Top
dfd3d90078 use of string_view in as<T> method (#1187)
Address Issue #881, allowing use of string_view in the as<XX> method on
options.

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2025-08-09 10:42:18 -04:00
Henry Schreiner
bb9bd85e3b chore: require CMake 3.14+ (#1182)
3.15 is a good minimum these days, and what pybind11, etc. now use.
(Edit: we are using some really old docker containers, so let's do 3.14+
for now).

---------

Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
2025-07-25 10:09:07 -04:00
Henry Schreiner
e351ddd522 chore: add CMake presets (#1181)
Add two presets (default and tidy).

---------

Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2025-07-25 10:05:37 -04:00
Philip Top
2a59b281f0 reorder the processing of requirements and callbacks. (#1186)
Check the requirements first.
Previously the callbacks were done first, but with custom callbacks this
cause side effects unexpectedly.

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2025-07-25 06:53:17 -07:00
Prashanth Mundkur
a9b7b96701 Update version in license to match source. (#1180)
For packagers that need to install license files, it helps when the
version in the license matches the version of the source used in the
package.
2025-07-24 06:28:37 -07:00
Philip Top
c5153634db Fix warnings and small issues (#1178)
try some things with no standard libraries
Add arm64 and freebsd build and tests
fix a discrepancy in the handling of chars on Arm processors

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2025-07-18 07:18:26 -07:00
pre-commit-ci[bot]
587129a170 chore(deps): pre-commit.ci autoupdate (#1177)
<!--pre-commit.ci start-->
updates:
- [github.com/pre-commit/mirrors-clang-format: v20.1.7 →
v20.1.8](https://github.com/pre-commit/mirrors-clang-format/compare/v20.1.7...v20.1.8)
<!--pre-commit.ci end-->

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2025-07-15 05:25:51 -07:00
pre-commit-ci[bot]
d0ac90b5f2 chore(deps): pre-commit.ci autoupdate (#1174)
<!--pre-commit.ci start-->
updates:
- [github.com/pre-commit/mirrors-clang-format: v20.1.6 →
v20.1.7](https://github.com/pre-commit/mirrors-clang-format/compare/v20.1.6...v20.1.7)
<!--pre-commit.ci end-->

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2025-07-14 11:30:33 -07:00
Dominik Nussbaumer
7a7ba4b9ca Allow rvalue references to be use with add_flag with no assignment (#1173)
I am starting to use CLI11 in a project and I came across an
inconvenience in code like this

```c++
const std::string description(std::format("description"));
app.add_flag("--flag", description);
```
As far as I can tell. I cannot directly use the description here. The
reason seems to be to distinguish between assignment and description. So
only `const std::string` or `const char*` and so on can be used here.
But a `const std::string &&` can not be used.

With the changes in the PR the code can also be written like this:
```c++
app.add_flag("--flag", std::format("description"));
```

The `add_flag` function can then be used with a const string or an
rvalue reference to a string.


A bit OT: I was a bit confused by this part of the existing comment ` if
a variable string is passed that variable will be assigned the results
from the flag` I think this might be wrong, but I am not sure.

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2025-06-27 06:36:06 -07:00
Philip Top
13658df9e1 remove use of windows-2019 image in azure CI tests (#1172)
Azure windows 2019 image is being deprecated, shift CI to windows-2022
and windows 2025 images
add tests for coverage and a few missing checks for duplication options.

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2025-06-18 20:19:28 -07:00
Philip Top
26bb3f2e30 More fuzzing2 (#1170)
add mechanic for fuzzing subcommands, and several fixes for found issues
from longer fuzzer runs

This includes some issues with option group positional name ambiguity, issue with join multioption policy and config files, and a few edge cases for configuration of multiline output interpretation.

Also added complex variables to the options, no issues found from this addition. 

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2025-06-18 05:21:18 -07:00
pre-commit-ci[bot]
569ca73b0b chore(deps): pre-commit.ci autoupdate (#1171)
<!--pre-commit.ci start-->
updates:
- [github.com/pre-commit/mirrors-clang-format: v20.1.5 →
v20.1.6](https://github.com/pre-commit/mirrors-clang-format/compare/v20.1.5...v20.1.6)
<!--pre-commit.ci end-->

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2025-06-17 06:07:57 -07:00
Philip Top
328ac68432 Subcommand plurality (#1169)
Partially address #1168 fix subcommand plurality when subcommand_max count is 0

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2025-06-05 17:48:01 -07:00
Theo Paris
542ef71d8d build: improve meson build (#1167)
Allows building the precompiled library as a shared library. This can be
toggled with the `default_library` meson option. Additionally I added
pkgconfig support and installation of the headers.
2025-06-03 08:07:20 -07:00
pre-commit-ci[bot]
4a4039d05c chore(deps): pre-commit.ci autoupdate (#1166)
<!--pre-commit.ci start-->
updates:
- [github.com/pre-commit/mirrors-clang-format: v20.1.4 →
v20.1.5](https://github.com/pre-commit/mirrors-clang-format/compare/v20.1.4...v20.1.5)
<!--pre-commit.ci end-->

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2025-05-29 04:56:00 -07:00
Philip Top
c4a6f31bd9 Tests (#1165)
Handle RTTI in a consistent way for locale inclusion for integral conversion.  
Resolve some missing code coverage lines.

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Alexander Galanin <agalanin@nvidia.com>
2025-05-26 10:35:22 -07:00
Alexander Galanin
3d9eb4e0a0 Default value conversion error if the application locale is set (#1160)
**Short description**
Application fails with `CLI::ConversionError` in some locales if the
application locale is set.

**Root cause**
CLI11 uses `std::stringstream` to format default value and
`strtol`/`strtod` to parse them back. The first method adds
locale-specific thousand separators but the second method parses the
number only up to the first separator. This causes an exception when the
same value is converted to string representation and then parsed back.

Examples: in _en_US_ locale 1234.56 is "1,234.56" and in de_DE locale
1234.56 is "1.234,56".

**Reproduction**
```c++
#include <string>
#include <CLI/CLI.hpp>

int main(int argc, const char **argv)
{
    std::locale::global(std::locale(""));
    CLI::App app{"Bug report app"};
    long foo;

    app.add_option("FOO", foo, "Foo option")
        ->envname("FOO")
        ->default_val(1234567);
    CLI11_PARSE(app, argc, argv);

    return 0;
}
```
Output:
```
$ g++ -Wall -Wextra -I CLI11/include/ cli11-bug-locale-string.cpp -o cli11-bug-locale-string
$ for locale in C en_US de_DE fr_FR de_CH; do echo "locale $locale"; LC_NUMERIC=$locale.UTF-8 ./cli11-bug-locale-string && echo OK; echo; done
locale C
OK

locale en_US
terminate called after throwing an instance of 'CLI::ConversionError'
what():  The value FOO is not an allowed value for given default value("1,234,567") produces an error : Could not convert: FOO = 1,234,567
Aborted (core dumped)

locale de_DE
terminate called after throwing an instance of 'CLI::ConversionError'
what():  The value FOO is not an allowed value for given default value("1.234.567") produces an error : Could not convert: FOO = 1.234.567
Aborted (core dumped)

locale fr_FR
terminate called after throwing an instance of 'CLI::ConversionError'
what():  The value FOO is not an allowed value for given default value("1 234 567") produces an error : Could not convert: FOO = 1 234 567
Aborted (core dumped)

locale de_CH
OK
```

**Fix description**
The fix strips group separators from the input string. This extends a
bit the logic introduced in change #968 for `_` and `'` separators.
There are no unit tests for the change because it requires to have all
mentioned locales to be installed in the system.

---------

Co-authored-by: Philip Top <phlptp@gmail.com>
2025-05-25 16:26:47 -07:00
Philip Top
5602f2b438 add an example of finding close matches (#1152)
continue discussion on #1149 
Adds subcommand prefix matching as a modifier to CLI.  
Adds an example of close matching logic for further exploration.

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2025-05-21 19:39:00 -07:00
Philip Top
50591fb666 Fuzz fail new (#1164)
Additional fuzz failures from longer runs of fuzzer.
Ran the fuzzer for a couple hours. Picked up a few interesting bug particularly in the config out and return.

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2025-05-21 19:37:28 -07:00
Philip Top
2c787a50ed add flags on the formatter to disable formatting (#1150)
add flags on the formatter to disable formatting for the description and
footer to allow things like word art or custom formatting.

One possible solution for #1145

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2025-05-19 05:25:00 -07:00
pre-commit-ci[bot]
1df96c852d chore(deps): pre-commit.ci autoupdate (#1163)
<!--pre-commit.ci start-->
updates:
- [github.com/pre-commit/mirrors-clang-format: v20.1.3 →
v20.1.4](https://github.com/pre-commit/mirrors-clang-format/compare/v20.1.3...v20.1.4)
<!--pre-commit.ci end-->

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2025-05-13 06:25:48 -07:00
Philip Top
990956f4f8 add checks and fixes for extrasError argument order (#1162)
Adds tests and checks for Extras Error 
Builds on #1158

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2025-05-09 08:06:25 -07:00
Alexander Galanin
1364746d4c Fix the order of arguments in command-line parsing error message (#1158)
CLI11 code prints the command-line arguments in reversed order in the
error message.

Code to reproduce:
```c++
#include <string>
#include <CLI/CLI.hpp>

int main(int argc, const char **argv)
{
    CLI::App app{"Bug report app"};
    std::string foo;

    app.add_option("--foo", foo, "Foo option");
    CLI11_PARSE(app, argc, argv);

    return 0;
}
```

Reproduction:
```
$ g++ -Wall -Wextra -I CLI11/include/ cli11-bug-order-in-error.cpp -o cli11-bug-order-in-error && ./cli11-bug-order-in-error --foo bar --fizz buzz
The following arguments were not expected: buzz --fizz
Run with --help for more information.
```
Expected result:
```
The following arguments were not expected: --fizz buzz
Run with --help for more information.
```
2025-05-09 05:35:05 -07:00
Philip Top
c31476b01a Multiple footer printing in help (#1161)
Fixes #1156 

For option groups removes inheritance of the footer and help option, so
those are not printed by default for option groups. It is still possible
to set them again on the option group.

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2025-05-08 06:17:18 -07:00
pre-commit-ci[bot]
f6328ccc7a chore(deps): pre-commit.ci autoupdate (#1159)
<!--pre-commit.ci start-->
updates:
- [github.com/pre-commit/mirrors-clang-format: v20.1.0 →
v20.1.3](https://github.com/pre-commit/mirrors-clang-format/compare/v20.1.0...v20.1.3)
<!--pre-commit.ci end-->

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2025-05-06 04:39:46 -07:00
Philip Top
3ed270937e fix an issue with default strings of arrays and config out. (#1155)
Fixes #1154

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2025-04-28 17:39:29 -07:00
Philip Top
cbbf20ed93 Ci build update (#1151)
update ci build images, remove ubuntu 20.04 and update a few others, fix some newer clang-tidy warnings

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2025-04-19 09:14:59 -07:00
Philip Top
70f98cb218 fuzzer failure --sub1.- interpreting as a short option (#1148)
and getting into odd situations

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2025-04-15 18:44:49 -07:00
huangqinjin
bc621a95ca Fix compilation on VS2017 (#1143)
The compiler complains about C2131: expression did not evaluate to a
constant.

https://godbolt.org/z/a198P3bdM

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2025-04-13 07:17:59 -07:00
Philip Top
a8d6b84cfc resolve ambiguity for vector<array> options (#1147)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2025-04-13 07:15:11 -07:00
pre-commit-ci[bot]
6fbdbaf308 chore(deps): pre-commit.ci autoupdate (#1142)
<!--pre-commit.ci start-->
updates:
- [github.com/pre-commit/mirrors-clang-format: v19.1.7 →
v20.1.0](https://github.com/pre-commit/mirrors-clang-format/compare/v19.1.7...v20.1.0)
<!--pre-commit.ci end-->

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2025-03-20 06:36:49 -07:00
Philip Top
2d79205521 Fix some minor fuzzing issues. (#1138)
One in the fuzz check handling of NaN's and a pathway to generate a
HorribleError.

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2025-03-11 18:21:46 -07:00
Philip Top
f871b625ee Float parsing negative (#1140)
Fixes #1139 
Fix a bug relating to parsing negative floating point values with no
zero before decimal point in a context where an option could be
possible.

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2025-03-11 07:08:38 -07:00
Philip Top
f75fd22ba3 add tests and fixes for array options (#1136)
Fixes #1135. Adds enable check to certain to_string functions as some
std::array operations were ambiguous.

The addition of the capability to convert tuples to strings created an
ambiguity in the case std::array, which acts like a tuple and a
container. So it worked with the container conversion before, but could
also work with the new tuple conversion. And we didn't have any tests to
catch this.

This PR resolves the ambiguity, and adds some tests to check that array
is handled well.

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2025-03-07 07:47:56 -08:00
allcontributors[bot]
8fa8a0fa0c 📝 Add ComixHe as a contributor for code (#1137)
Adds @ComixHe as a contributor for code.

This was requested by phlptp [in this
comment](https://github.com/CLIUtils/CLI11/pull/1132#issuecomment-2702742598)

[skip ci]

---------

Co-authored-by: allcontributors[bot] <46447321+allcontributors[bot]@users.noreply.github.com>
2025-03-05 20:34:07 -08:00
Comix
7ff65c16f2 fix: promoting uint8_t/int8_t to make it casting result printable (#1132)
The underlying type of uint8_t/int8_t is unsigned char and signed char,
but IOStreams was specified to treat them just like char.

so promoting the casting value to get the expected value.

Signed-off-by: ComixHe <ComixHe1895@outlook.com>
2025-03-05 20:07:50 -08:00
allcontributors[bot]
38e370f671 📝 Add gblanco92 as a contributor for code (#1131)
Adds @gblanco92 as a contributor for code.

This was requested by phlptp [in this
comment](https://github.com/CLIUtils/CLI11/pull/1129#issuecomment-2694425412)

[skip ci]

---------

Co-authored-by: allcontributors[bot] <46447321+allcontributors[bot]@users.noreply.github.com>
2025-03-04 06:53:37 -08:00
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
0eb88ed958 add option modifiers pathways to custom options in the fuzzer (#1128)
Next phase of the fuzzer, adds some mechanics for the fuzzer itself to
add modifiers on the options.

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2025-03-03 04:54:46 -08:00
Philip Top
4160d259d9 update version and changelog for 2.5 release (#1121)
update readme, changelog, and version for 2.5 release

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Henry Schreiner <HenrySchreinerIII@gmail.com>
v2.5.0
2025-02-27 04:25:31 -08:00
allcontributors[bot]
a48f049365 📝 Add jmarrec as a contributor for code (#1127)
Adds @jmarrec as a contributor for code.

This was requested by phlptp [in this
comment](https://github.com/CLIUtils/CLI11/pull/1122#issuecomment-2682507198)

[skip ci]

---------

Co-authored-by: allcontributors[bot] <46447321+allcontributors[bot]@users.noreply.github.com>
Co-authored-by: Philip Top <phlptp@gmail.com>
2025-02-25 16:19:35 -08:00
allcontributors[bot]
091d4cfb3b 📝 Add nshaheed as a contributor for platform (#1126)
Adds @nshaheed as a contributor for platform.

This was requested by phlptp [in this
comment](https://github.com/CLIUtils/CLI11/pull/1122#issuecomment-2682506808)

[skip ci]

---------

Co-authored-by: allcontributors[bot] <46447321+allcontributors[bot]@users.noreply.github.com>
Co-authored-by: Philip Top <phlptp@gmail.com>
2025-02-25 14:10:38 -08:00
allcontributors[bot]
8d5d0967a0 📝 Add j-rivero as a contributor for platform (#1124)
Adds @j-rivero as a contributor for platform.

This was requested by phlptp [in this
comment](https://github.com/CLIUtils/CLI11/pull/1122#issuecomment-2682497166)

[skip ci]

---------

Co-authored-by: allcontributors[bot] <46447321+allcontributors[bot]@users.noreply.github.com>
Co-authored-by: Philip Top <phlptp@gmail.com>
2025-02-25 13:37:15 -08:00
allcontributors[bot]
8fcbddadd3 📝 Add krico as a contributor for code (#1125)
Adds @krico as a contributor for code.

This was requested by phlptp [in this
comment](https://github.com/CLIUtils/CLI11/pull/1122#issuecomment-2682503164)

[skip ci]

---------

Co-authored-by: allcontributors[bot] <46447321+allcontributors[bot]@users.noreply.github.com>
2025-02-25 12:00:31 -08:00
allcontributors[bot]
65220bd28a 📝 Add jsoref as a contributor for doc (#1123)
Adds @jsoref as a contributor for doc.

This was requested by phlptp [in this
comment](https://github.com/CLIUtils/CLI11/pull/1122#issuecomment-2682493678)

[skip ci]

---------

Co-authored-by: allcontributors[bot] <46447321+allcontributors[bot]@users.noreply.github.com>
2025-02-25 08:34:26 -08:00
allcontributors[bot]
6193e56935 📝 Add LostInCompilation as a contributor for code (#1122)
Adds @LostInCompilation as a contributor for code.

This was requested by phlptp [in this
comment](https://github.com/CLIUtils/CLI11/pull/1121#issuecomment-2682455232)

[skip ci]

---------

Co-authored-by: allcontributors[bot] <46447321+allcontributors[bot]@users.noreply.github.com>
2025-02-25 08:33:53 -08:00
pre-commit-ci[bot]
a05601a968 chore(deps): pre-commit.ci autoupdate (#1117)
<!--pre-commit.ci start-->
updates:
- [github.com/psf/black: 24.10.0 →
25.1.0](https://github.com/psf/black/compare/24.10.0...25.1.0)
- [github.com/codespell-project/codespell: v2.4.0 →
v2.4.1](https://github.com/codespell-project/codespell/compare/v2.4.0...v2.4.1)
<!--pre-commit.ci end-->

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2025-02-04 06:09:44 -08:00
pre-commit-ci[bot]
5ed9783d78 chore(deps): pre-commit.ci autoupdate (#1116)
<!--pre-commit.ci start-->
updates:
- [github.com/pre-commit/mirrors-clang-format: v19.1.6 →
v19.1.7](https://github.com/pre-commit/mirrors-clang-format/compare/v19.1.6...v19.1.7)
- [github.com/codespell-project/codespell: v2.3.0 →
v2.4.0](https://github.com/codespell-project/codespell/compare/v2.3.0...v2.4.0)
<!--pre-commit.ci end-->

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Philip Top <phlptp@gmail.com>
2025-01-28 06:15:17 -08:00
Philip Top
92adf2c8c2 Allow trailing spaces on strings for conversions (#1115)
Allow trailing spaces on strings for conversions to floating point and
integers.

There was a potential confusing error that could occur if strings with
trailing spaces were converted to integer or floating point values. This
PR allows trailing spaces in the strings that would otherwise be
convertible to the appropriate numerical type.

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2025-01-27 19:14:18 -08:00