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>
Add modifier for subcommands to restrict subcommands falling through to
parent.
This will resolve#1022
---------
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
_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>
Fix docstring related to #1052
Fix config_to_string with defaults #1007
---------
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This PR adds a mechanism to hide groups but have their options visible
as part of the parent.
This works for option group names starting with a '+'
for example
```
CLI::App app;
bool flag = false;
std::optional<bool> optional_flag = std::nullopt;
app.add_option("--tester");
auto *m1=app.add_option_group("+tester");
m1->add_option("--flag", flag, "description");
m1->add_option("--optional_flag", optional_flag, "description");
CLI11_PARSE(app,argc, argv);
```
will produce help as
```txt
Options:
-h,--help Print this help message and exit
--tester
--flag BOOLEAN description
--optional_flag BOOLEAN description
```
instead of
```
Options:
-h,--help Print this help message and exit
--tester
[Option Group: tester]
Options:
--flag BOOLEAN description
--optional_flag BOOLEAN description
```
Fixes issue #1034 and a few other past issues or questions
---------
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
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>
get_subcommand when used for parsing config files, was throwing and
catching as part of control flow and expected operation, this resulting
in a performance hit in select cases. A get_subcommand_no_throw was
added to resolve this issue.
---------
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Correct an anomaly when using config file processing with a default. In
this case the count always shows 1 even if the default file were not
actually used. This caused some issues in some applications and was a
change from previous versions.
---------
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Fixes#845 as discussed.
Comparing the two approaches of getting `argv`:
1. The "old" way, through `CLI::argv()`:
✔️ Works automatically and almost everywhere
❌ Small abstraction overhead on macOS
❌ Does not work in weird edge-cases such as missing `/proc`
2. This PR, through `app.ensure_utf8`:
✔️ True zero-overhead abstraction: you don't pay for what you don't use
✔️ Less moving parts than the "old" approach, probably can't be broken
❌ Requires extra code to be written by the user (which is sad because
ideally everyone should use this by default)
---------
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
use it for the default in `set_config` and simplify and add more
flexibility to the the config processing, and potentially in other
options as well.
The reverse policy returns a vector but in reversed order from normal.
This is what we want in the config processing
Inspired by #862, and updated with recent code changes.
---------
Co-authored-by: Volker Christian <me@vchrist.at>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
* Add unicode support tests
* Add unicode parse tests
* Implement #14
* Slim down Windows.h
* Fix documentation comments
* Fix clang-tidy and cpplint
* Update README
* Fix clang-tidy
* Fix to_path not being available on linux
* Add roundtrip encoding tests
* style: pre-commit.ci fixes
* Fix pre-commit.ci
* Fix codacy
* Exclude parse_unicode which should not contain a newline from pre-commit
* Remove a test which breaks CI
* Fix build in CI
* Replace broken execute_with tests
* Fix wide string conversions on all systems
* Fix system args on apple
* style: pre-commit.ci fixes
* Fix some includes
* Fix wrong size calculation and comments
* Add guards around codecvt
* Fix _Pragma not recognized on MSVC
* Fix bad macro check
* Fix include
* Fix narrow and widen when codecvt is missing
* Fix some weird bug in old MSVC
* Add dependent applications to meson-build
* Fix precompilation
* Fix lint
* Fix coverage
* Update README
* style: pre-commit.ci fixes
* Fix lint
* Fix coverage
* Fix optional braces offending clang
* Remove copied comments from Windows.h
* Suppress flawfinder detects
* Fix cmake config tests failing because of a missing lib
* chore: update copyright on new files to 2023
Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
* style: pre-commit.ci fixes
Signed-off-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>
* Allow using dot notation for subcommand arguments such as --sub1.field
* add tests for dot notation for subcommands
* style: pre-commit.ci fixes
* add test for short form arguments in dot notation
* style: pre-commit.ci fixes
* add _pre_parse_callback_ support using dot notation
* style: pre-commit.ci fixes
* update cmake tests to include 3.24
* change line endings
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
* fix: show newline before footer only if footer is set and not empty
* feat: added usage message replacement feature
* fix: tests corrected for new help message formatting
* Using ADL everywhere for lexical_cast
* Fixes in docs
* Add a test for old extension mechanism
* style: pre-commit.ci fixes
* Make gcc happy
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Philip Top <phlptp@gmail.com>
* add some warning for GCC output
* fix some warnings
* style: pre-commit.ci fixes
* update ubuntu image used for cmake tests so it doesn't auto transition to 22.04
* try a few more warning flags
* install the correct files
* style: pre-commit.ci fixes
* fix install files
* add a few more things to pre-commit
* try a fix for codacy
* another try at codecov
* more coverage tweaks
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
- Add C11_COMPILE cmake option that creates a static lib instead of header-only
- Add C11_INLINE macro that depends on C11_COMPILE
- Split App.hpp into App.hpp and impl/App_inl.hpp
- Add App.cpp that compiles App_inl.hpp into an object file
- CMake modifications to handle impl headers differently for sinlge-header, headers-only, and compiled versions
* fix the issue where subcommand callbacks would be triggered multiple times if specified as configurable.
* style: pre-commit.ci fixes
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
* 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>
* 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>
* add tests which suppose to pass
* Update ConfigFileTest.cpp
* Update ConfigFileTest.cpp
* style: pre-commit.ci fixes
* add the possibility for an empty vector result if allowed.
* style: pre-commit.ci fixes
* add empty vector command line tests
* update book and readme
* add no default test
Co-authored-by: puchneiner <90352207+puchneiner@users.noreply.github.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
* add an option to validate optional arguments like in a vector. This can resolve some issues with separating positionals from vector arguments
* style: pre-commit.ci fixes
* add some updates to the book
* style: pre-commit.ci fixes
* fix some precommit issues
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
* add a few tests related to github issues
* change how the default is displayed in the help message prev was =XXXX, this was confusing in some cases particularly with flags or with multiple option names. Now is [default=XXXX] which makes it clearer what the value represents.
* Try to fix RTTI issue
* style: pre-commit.ci fixes
* Fix subcommand callbacks being called multiple times if in an option group
* style: pre-commit.ci fixes
* remove extra group call
* change [default=XXXXD] to just [XXXXX] for the default specification
* update changelog
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
* 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>
* add some capabilities to the config parser and a stream parser
* style: pre-commit.ci fixes
* add additional tests for the config parser
* additional tests of config sections and indexing
* style: pre-commit.ci fixes
* add initialization for member variables
* warning and error fixes
* add test for `parse_from_stream`
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
* 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>
* Fix excessive call to subcommand's final_callback
When parse_complete_callback_ is set there is an extra call to
run_callback() inside the App::_parse(std::vector<std::string>&) method.
This extra call also excessively calls a final_callback_ (when it is
also set) for the command and (since it is recursive) for it's
subcommands.
This commit adds extra boolean parameter for the run_callback() method
allowing to explicitly suppress calling to final_callback_. The value of
this parameter is also propagated to recursive calls to run_callback().
Fixes#572
* fix: main app should run final_callback, add tests
Co-authored-by: Henry Schreiner <henryschreineriii@gmail.com>