max, min on positional was not respected, specifically max positionals
only filled up to min, and skipped over optional options.
Fixes#1090
---------
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Fixes issue #1086.
In the default_val enums of uint8_t would read in as a string as they
could be converted to a string. This worked ok for normal values, but
when a check was added for specific strings, it caused an error when the
default_val was added. This PR fixes the issue.
The builder for coverage was updated to CMake 3.31 (by github), this
triggered an error in the coverage tool script. This led to updating
that script, which led to uncovering some missing coverage, which led to
additional tests, which led to some issues around single element tuples
support from #1081, which led to a few other issues that came up in the
to_string operation and templates.
---------
Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
add capability to accept pair/tuple default values and a little cleaner
parsing in some cases
Fixes#711
---------
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
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>
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>
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>
Add escaping to quoted strings, differentiate between literal and
regular strings.
The goal is to make string processing in config files as close as
possible to toml standards. This means handing escape sequences
including unicode, and differentiating between literal strings and
regular strings in files and when splitting the command line. Also
allowing variable names in the files to be quoted.
This PR gets partway there. Removes some hacks from the previous PR to
deal with unusual option names and replaces with the quoted names.
---------
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
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>
remove old code since all arguments are quoted now and the code was not
being used, add coverage exclusion on some code that should never be
executed and add an additional test
---------
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Add some additional tests to try to get test coverage back to 100%
refactor the positional parsing to reduce code duplication
---------
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>
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>
to handle `std::filesystem::path` better widestring operations should be
preferred over regular strings.
Fix Issue #875
---------
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>
* 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>
* add some more tests for coverage and fix some confusing error situations with config files.
* style: pre-commit.ci fixes
* fix warning
* ci: fix coverage
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 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>
* 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>
* update the range error output to be able to be used by more types, and better printouts in some situations.
* style: pre-commit.ci fixes
* add test
* style: pre-commit.ci fixes
* fix the test
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 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>
* 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>
* add a get_single_name function for options, and allow short names to be used for configuration output.
* add config input to handle short and positional options
* add some tests about short options and positional options in config files
* allow use of envname_ in config files
* update doc book and readme with fixes
* formatting update
* some formatting updates
* add some notes on the config file generation
* just try modifying a comment
* 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
* add a variant of the string conversions for the default string operations. Discriminate between the is_convertible and is_constructible type traits for object.
* update the test to test the different situations with the funny string like type
* work on the flags book chapter and making sure the values are initialized properly.
* Fix initialization of values used in flags or options
* update some formatting and more brace initialization
* update more formatting and fix a incorrect initializer
* more formatting and some error fixes
* more formatting
* Small formatting fix
Co-authored-by: Henry Schreiner <HenrySchreinerIII@gmail.com>