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 mechanics for the fuzzer to add custom options.
---------
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Since Monterey 12.3, macOS removed python2.7 from it's base
installation. This means that `python` is not longer a command by
default (just `python3`), and the build for CLI11 fails. This PR moves
to using `pymod.find_installation()` to handle this in a more general
way. See https://mesonbuild.com/Python-module.html
Close#688
Adds an example on how to use transform validator objects and clarifies
the usage of the return type of the base function.
---------
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
- Polish empty lines and disable description printing for apps and
subcommands with empty name, empty group and with no options and
subcommands.
- Add commentDefaults() method to trigger to comment default value
options in case default_also is true, so that the result set of an
option is not pollute with default option values.
- In case dafault_also is true mark required but not yet configured
options as "<REQUIRED>" and not yet configured default options as "" in
a commented line in the config file.
---------
Co-authored-by: Volker Christian <volker.christian@fh-hagenberg.at>
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>
Example of help modification as documentation supplement.
---------
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Philip Top <top1@llnl.gov>
Co-authored-by: Philip Top <phlptp@gmail.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>
From #1067, there is a bit of ambiguity in the handling of config file
with vector input and multiple consecutive parameters. For example
```toml
option1=[3,4,5]
option1=[4,5,6]
```
Currently this is handled as if it were
```toml
option1=[3,4,5,4,5,6]
```
But this could be confusing in the case where the input was referring to
a vector of vectors.
This PR adds a separator in the sequence to separate the vector so they
are two vectors of 3 elements each.
Will need to verify if this change has other side effects. It is a
pretty unusual situation.
---------
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
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>
Greetings, fellow CLI11 community!
We have just added the latest version of cli11 to [Conan
Center](https://conan.io/center/recipes/cli11?version=2.4.2) and thought
it would be a nice addition to include instructions on how to install
CLI11 via Conan in the book folder.
Please let me know if this is okay, or if you would prefer it placed
elsewhere.
**UPDATE**: Some extra information to be more clear about the used
command line and links:
I did not mention how to install/configure Conan, because both links to
conan.io and conan-center-index has all Conan documentation updated. For
instance: https://conan.io/downloads
The latest version of CLI11 available in Conan Center is 2.4.2:
- https://conan.io/center/recipes/cli11?version=2.4.2
or, can be found by running the conan command:
conan search "cli11"
The command `conan install --requires="cli11/[*]" --build=missing`
means:
* conan install: Install a package from a remote. By default, it points
to the official Conan Center
* --requires="cli11/[*]": Install the latest version of CLI11 available
in Conan Center
* --build=missing: In case not finding a pre-built package compatible,
build it from source then.
Regards!
---------
Signed-off-by: Uilian Ries <uilianries@gmail.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.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>
Take the configurability of an option into account when determining
ambiguous names and conflicts.
---------
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>
Prepare for release.
---------
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: Philip Top <phlptp@gmail.com>
Also works for overloads constrained with concepts or requirements.
Previously this wasn't working, which is a problem if you want to hook
some external serialization framework into CLI11 without painstakingly
going through all the types that said external framework supports.
This PR is related to https://github.com/CLIUtils/CLI11/issues/908.
This is follow up work to my previous series. I've tried to make the
Meson build mirror the CMake build more closely. I've also made an
attempt at adding some instructions to the documents on using Meson.
---------
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>
Adds support for building with Bazel. If merged, I can push this to
https://registry.bazel.build/ when a new release is cut :)
---------
Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
Co-authored-by: Caleb Zulawski <caleb.zulawski@caci.com>
Co-authored-by: Henry Schreiner <henryschreineriii@gmail.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
See https://github.com/CLIUtils/CLI11/pull/1025.
---------
Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
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
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>
This series cleans up and modernizes the Meson code a bit:
- It adds the license SPDX name to the proper field
- Sets a minimum version, the version is fairly old, but without setting
a version then Meson will never warn about issues, including potentially
important ones like "this happens to work in some cases but wasn't
intended and doesn't work in all cases"
- uses more modern Meson features to make things easier for consumers
- Fixes the tests using the ensure_utf8 helpers by ensuring that they're
actually built, and placing them in the correct path.
- Adds the Meson test to the CI
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>
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, and makes it harder to make CLI11 part of a
larger codebase.
This is a regression of #475.
Bumps the actions group with 1 update:
[softprops/action-gh-release](https://github.com/softprops/action-gh-release).
Updates `softprops/action-gh-release` from 1 to 2
<details>
<summary>Release notes</summary>
<p><em>Sourced from <a
href="https://github.com/softprops/action-gh-release/releases">softprops/action-gh-release's
releases</a>.</em></p>
<blockquote>
<h2>v2.0.0</h2>
<ul>
<li>update actions.yml declaration to node20 to address warnings</li>
</ul>
</blockquote>
</details>
<details>
<summary>Changelog</summary>
<p><em>Sourced from <a
href="https://github.com/softprops/action-gh-release/blob/master/CHANGELOG.md">softprops/action-gh-release's
changelog</a>.</em></p>
<blockquote>
<h2>0.1.12</h2>
<ul>
<li>fix bug leading to empty strings subsituted for inputs users don't
provide breaking api calls <a
href="https://redirect.github.com/softprops/action-gh-release/pull/144">#144</a></li>
</ul>
</blockquote>
</details>
<details>
<summary>Commits</summary>
<ul>
<li><a
href="d99959edae"><code>d99959e</code></a>
prep release</li>
<li><a
href="0e39c679e8"><code>0e39c67</code></a>
make pattern error opt in (<a
href="https://redirect.github.com/softprops/action-gh-release/issues/417">#417</a>)</li>
<li><a
href="20e085ccc7"><code>20e085c</code></a>
kick off 2.0.1 release</li>
<li><a
href="9f5c4d39bc"><code>9f5c4d3</code></a>
update changelog</li>
<li><a
href="0bea76b227"><code>0bea76b</code></a>
Add support for make_latest property (<a
href="https://redirect.github.com/softprops/action-gh-release/issues/304">#304</a>)</li>
<li><a
href="762fe13dfb"><code>762fe13</code></a>
typo in changelog</li>
<li><a
href="c0f2569fb9"><code>c0f2569</code></a>
remove unused script</li>
<li><a
href="5743e06024"><code>5743e06</code></a>
update changelog</li>
<li><a
href="fe71fd3b91"><code>fe71fd3</code></a>
Don't swallow errors (<a
href="https://redirect.github.com/softprops/action-gh-release/issues/384">#384</a>)</li>
<li><a
href="9150ab13f3"><code>9150ab1</code></a>
rebuild and update changelog</li>
<li>Additional commits viewable in <a
href="https://github.com/softprops/action-gh-release/compare/v1...v2">compare
view</a></li>
</ul>
</details>
<br />
[](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores)
Dependabot will resolve any conflicts with this PR as long as you don't
alter it yourself. You can also trigger a rebase manually by commenting
`@dependabot rebase`.
[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)
---
<details>
<summary>Dependabot commands and options</summary>
<br />
You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits
that have been made to it
- `@dependabot merge` will merge this PR after your CI passes on it
- `@dependabot squash and merge` will squash and merge this PR after
your CI passes on it
- `@dependabot cancel merge` will cancel a previously requested merge
and block automerging
- `@dependabot reopen` will reopen this PR if it is closed
- `@dependabot close` will close this PR and stop Dependabot recreating
it. You can achieve the same result by closing it manually
- `@dependabot show <dependency name> ignore conditions` will show all
of the ignore conditions of the specified dependency
- `@dependabot ignore <dependency name> major version` will close this
group update PR and stop Dependabot creating any more for the specific
dependency's major version (unless you unignore this specific
dependency's major version or upgrade to it yourself)
- `@dependabot ignore <dependency name> minor version` will close this
group update PR and stop Dependabot creating any more for the specific
dependency's minor version (unless you unignore this specific
dependency's minor version or upgrade to it yourself)
- `@dependabot ignore <dependency name>` will close this group update PR
and stop Dependabot creating any more for the specific dependency
(unless you unignore this specific dependency or upgrade to it yourself)
- `@dependabot unignore <dependency name>` will remove all of the ignore
conditions of the specified dependency
- `@dependabot unignore <dependency name> <ignore condition>` will
remove the ignore condition of the specified dependency and ignore
conditions
</details>
Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Fix an issue with environmental variable parsing in option_groups, and
an issue with remaining in config files.
---------
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Quick release fixing the missing header.
---------
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: Philip Top <phlptp@gmail.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>
Fix https://github.com/CLIUtils/CLI11/issues/999.
This looks like about what we have to do. This test seems to be missing
from Meson, so don't have a workaround there yet.
Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
Fix#993. I tried include-what-you-use, but it reports too much stuff to
be able to pick out what's missing very effectively.
Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>