1
0
mirror of https://github.com/CLIUtils/CLI11.git synced 2025-04-29 12:13:52 +00:00

25 Commits

Author SHA1 Message Date
Philip Top
f41e59b7f6
fix a fuzzing issue from a string as a bracket (#1110)
fix fuzzing issue

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2025-01-03 07:47:09 -08:00
Philip Top
5a03ee5838
Allow non standard option names like -option (#1078)
This has been bounced around for a couple years now 

#474 and a few others have expressed desire to work with non-standard
option names. We have been somewhat resistant to that but I think it can
be done now. This PR adds a modifier `allow_non_standard_option_names()`
It is purposely long, it is purposely off by default. But what it does
is allow option names with a single `-` to act like a short option name.
With this modifier enabled no single letter short option names are
allowed to start with the same letter as a non-standard names. For
example `-s` and `-single` would not be allowed.

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Henry Schreiner <HenrySchreinerIII@gmail.com>
2024-10-23 05:14:29 -07:00
Marc
65442ad846
A better Help formatter (V2) (#866)
_This is the new PR I've mentioned to work on in PR #858_

## A better Help Formatter
_See below for images of the new help page_

Finally, after a lot of planning, understanding CLI11's codebase,
testing and coding, the new default Help Formatter is done. There are a
lot of changes to make the help page more readable and closer to UNIX
standards, see Changelog below for details. One of the highlights is
automatic paragraph formatting with correct line wrapping for App and
options/flag descriptions as well as the footer.
A goal was to provide more flexibility and better readability for the
help page while providing full compatibility with Apps using CLI11 (no
breaking changes and no changes to Apps required). Also better support
for different terminal sizes. Users can now specify three new optional
attributes: `right_column_width_`, `description_paragraph_width_` and
`footer_paragraph_width_`. See code documentation for more details. The
different columns for options/flags now scale with the set
`column_width_` value: Single dash flags occupy 33% of the set
`column_width_`, double dash flags and options (like REQUIRED) 66%.
These new attributes allow for indirectly respecting terminal geometry,
footer paragraph formatting has also been added (#355). This PR also
implements the issues #353 and #856.
The new help page formatting can also be used as an input for man page
generation, since it's oriented on the man page style (#413).
[help2man](https://www.gnu.org/software/help2man/) can be used to
generate man pages from help output (see comment down below for
example).

I thoroughly tested this code with all possible combinations of flags,
options, positionals, subcommands, validators, ...
So far everything works great.
I hope this PR looks good and meets all requirements. I'm looking
forward to the implementation of this PR into CLI11. If you have any
questions or suggestions feel free to comment.

### Fixed/implemented issues by this PR
- #353 Better options formatting
- #856 Space between options
- #355 Footer formatting
- #413 Man page generation can be achieved using help2man with the new
help formatting
- https://github.com/CLIUtils/CLI11/issues/384#issuecomment-570066436
Better help formatting can be marked as complete

### What about the failing tests?
Of course the tests expect the old help text format. This is why 6 of
the tests are failing. Since it is a bit of work to migrate the tests to
the new help format, I first wanted to push out this PR and get
confirmation before I'll update all the tests.
So please let me know if this PR gets implemented, what changes should
be made and then I'll migrate the tests to the new help format, either
in this PR or I'll make a new one.

## Changelog:
#### There are _no breaking changes_. Every App using CLI11 will work
with this new formatter with no changes required.
- Added empty lines at beginning and end of help text
- Removed double new-line between option groups for consistency. Now all
sections have the same number of new-lines
- Switched usage and description order
- Only show "Usage"-string if no App name is present. This provides
better readability
- Made categories (Options, Positionals, ...) capital
- Changed `ConfigBase::to_config` to correctly process capital
"OPTIONS"-group (only affects descriptions of the config file, not a
breaking change)
- Added a paragraph formatter function `streamOutAsParagraph` to
StringTools.hpp
- Made "description" a paragraph block with correct, word respecting
line wrapping and indentation (using the new paragraph formatter
function)
- Made the footer a paragraph block with correct, word respecting line
wrapping and indentation
- Updated documentation for `column_width_` to make it more clear
- Added new member: `right_column_width_`, added getter and setter for
`right_column_width_`
- Added new member: `description_paragraph_width_`, added getter and
setter for `description_paragraph_width_`
- Added new member: `footer_paragraph_width_`, added getter and setter
for `footer_paragraph_width_ `
- Positionals description are now formatted as paragraph with correct,
word respecting line wrapping
- Options description are now formatted as paragraph with correct, word
respecting line wrapping
- Short and long options/flags/names are now correctly formatted to
always be at the right position (also for subcommand options/flags)
- Short and long options/flags/names column widths scale linearly with
the `column_width_` attribute to better adapt to different
`column_width_` sizes
- Merged PR #860

## What's planned for the future?
- I'm thinking of better formatting the options of flags (like REQUIRED,
TEXT, INT, ...) and make them also in a seperate column. This way they
would also always be at the same position. However I decided against it
for this PR, since I wanted them to be as close as possible to the
actual flag. With my implementation it is quite easy to add this change
in the future.
- Subcommands: I'm planning on better formatting the Subcommands. With
this PR only the short and long flags/options of subcommands are better
formatted (like it is with the main flags, see images down below).
- Maybe implement a different way to display expected data type options
(TEXT, INT, ...). For example: `--file-name=<TEXT>` for long flags only
and if `disable_flag_override_` is false.
- Maybe add something like this:
https://github.com/CLIUtils/CLI11/issues/554

---------

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-10-07 08:13:04 -07: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
Henry Schreiner
20de8b73bb
tests: fix catch2 3 support (#980)
Is there an easy way to pre-install this in CI or download it (perhaps
in meson)? It's bad that we aren't running in CI with version 3 (but
don't want to drop 2, since we can't drop it until we drop C++11).

---------

Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2024-01-12 17:43:17 -05:00
Philip Top
9dfeefe2ba
update copyright date to 2024 (#971)
update copyright dates
2024-01-06 08:08:31 -08:00
Philip Top
91101604d5
Support all capabilities for toml integers and floating point numbers (#968)
This PR add support for all TOML integer types.
This includes 
```
{"+99", 99},
    { "99",99 },
    { "0xDEADBEEF",0xDEADBEEF },
    { "0xdeadbeef",0xDEADBEEF },
    { "0xdead_beef",0xDEADBEEF },
    { "0xdead'beef",0xDEADBEEF },
    { "0o01234567",001234567 },
    { "0o755",0755 },
    { "0755",0755 },
    { "995862_262",995862262 },
    { "995862262",995862262 },
    { "+995862275",+995862275 },
    { "995'862'275",995862275 },
    {"0b11010110",0xD6},
    {"0b1101'0110",0xD6},
    {"1_2_3_4_5",12345},
```

So support for separators (Toml and C++ standards), binary(new),
hex(worked previously), and octal(new)

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2024-01-02 06:56:46 -08:00
Philip Top
0a615f854d
fix: issue found by fuzzing (#846)
* Add the beginnings of a fuzzing system for CLI11.  This commit adds the fuzzing code, a simple test, and two fixes to issues(seg faults) found by the initial round of fuzzing.  It also adds a few tests and coverage issues uncovered in the process of developing the fuzz tests. As a side effect adjusts some of the azure tests to specify the vmImage which was being changed on azure.

* update license to match rest of code base

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2023-03-09 15:02:49 -05:00
Philip Top
39a5f1981e
chore: update copyright year to 2023 (#825) 2023-01-03 17:29:37 -05:00
Philip Top
ca9a128720
test for out of bounds long long (#807)
* test for out of bounds long long

* style: pre-commit.ci fixes

* change to use std types

* style: pre-commit.ci fixes

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2022-11-30 15:41:34 -08: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
f7d26f26b2
feat: counting flags (#709)
* add a counting flag to address and issue with optional<bool>  and make the flags more consistent

* move the add_flag to a single operation and add a Sum multi option policy

* style: pre-commit.ci fixes

* remove sum_flag_vector overloads

* style: pre-commit.ci fixes

* add limits include

* style: pre-commit.ci fixes

* fix some other warnings

* update docs describing the multi_option_policy

* Apply suggestions from code review

Co-authored-by: Henry Schreiner <HenrySchreinerIII@gmail.com>

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Henry Schreiner <HenrySchreinerIII@gmail.com>
2022-03-21 18:56:35 -04:00
Philip Top
95e7f81d1d
fix: trigger on parse positional (#713)
* allow the trigger on parse modifier to work with positional arguments as well

* style: pre-commit.ci fixes

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2022-03-21 17:51:08 -04:00
Philip Top
815553211b
fix and test some reported issues (#661) 2021-11-01 23:12:55 -04:00
Philip Top
6c49c299b9
feat: add a more clear force callback (#631)
* Add some missing modifiers on the options to the docs and clarify some of them.

* style: pre-commit.ci fixes

* add a more clear force callback and callback on parse modifier for options.

* update the book with new modifiers

* update documentation and add tests

* style: pre-commit.ci fixes

* more updates to the readme

* update formatting

* rework the trigger_on_parse to better support more complex option types

* fix formatting errors

* Update include/CLI/Option.hpp

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Henry Schreiner <HenrySchreinerIII@gmail.com>
Co-authored-by: Henry Schreiner <henry.fredrick.schreiner@cern.ch>
2021-09-20 10:23:39 -04:00
Philip Top
19047d8d68
feat: relaxed option naming (#627)
* add a test for std::map

* add some test of the relaxed naming and other checks

* add validator for aliases, group names and option groups

* add extra tests and update readme

* style: pre-commit.ci fixes

* update the book chapters

* fix codacy issue

* Apply suggestions from code review

Co-authored-by: Henry Schreiner <HenrySchreinerIII@gmail.com>

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Henry Schreiner <HenrySchreinerIII@gmail.com>
2021-08-22 23:52:00 -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
e2e3cb2fed
refactor!: drop defaulted from add_option (#597) 2021-06-16 11:16:22 -04:00
Henry Schreiner
5d12e11d8a tests: use catch2 2021-04-04 00:29:21 -04:00
Philip Top
89926dc820
feat: support for Atomic types in flags and options (#520) 2020-10-28 11:57:47 -04:00
Philip Top
438eabe5f8
feat: add char type (#449)
add a test for char options

add support for char types to the lexical cast, to allow single character types that make sense, add a integral_conversion operations to simplify the conversions from string to integers and allow discrimination in a few cases with enumerations.
2020-09-30 17:58:39 -04:00
Philip Top
34bd80971b
allow the use of allow_extra_args(false) to specify only a single argument at a time with a container output. (#484) 2020-07-24 00:02:33 -04:00
c.bachhuber
7432ab264d Fix code style
Format
2020-03-23 09:42:08 -04:00
Philip Top
27da2f952e
Container options (#423)
* Update options.md book chapter and the readme to better reflect current usage and the modifications to the add_options templates.

add support in add_option for wrapper types, such as std::optional, boost::optional or other types with a value_type trait.  Add support for generalized containers beyond vector,  add support for nested tuples and vectors, and complex numbers directly in add_option.  This includes several new type traits and object categories.

Upgrade the google test version to better support templated tests.

add support for vector argument separator `%%`

* update formatting to match recent changes

* Apply suggestions from code review

Co-authored-by: Henry Schreiner <HenrySchreinerIII@gmail.com>
2020-03-22 14:06:34 -04:00