Commit Graph

94 Commits

Author SHA1 Message Date
Nitin Kumar 370de72bfe
feat: allow arbitrary char in opt name (#491)
* feat: Allow arbitrary characters
2026-02-23 18:14:43 +11:00
Nitin Kumar a0f13a1528
fix: Fix short options parsing with equal sign (#488)
* feat: Add test for short options parsing

* fix: Update option parsing to allow = with short options

* fix: Fix custom option parsing in case of CXXOPTS_NO_REGEX
2026-02-02 17:37:12 +11:00
Nitin Kumar b39f57f6bc
fix: Add ci test for options_no_regex, and fix inconsistency between regex pattern and customer parser (#487)
* chore(ci): Add test for options_no_regex

* fix: Fix regex parsing for CXXOPTS_NO_REGEX
2026-01-29 18:02:15 +11:00
Nitin Kumar 89985f820e
feat: Switch to stable_partition to ensure that only first long options is printed in help (#481)
* feat: Add test for Ordering of multiple long options

* fix: Use stable_partition for deterministic ordering
2026-01-14 06:57:04 +11:00
Dylan Baker 0f1c5a0a79
Add Meson buildsystem support (#424)
* meson: Add a Meson based build system

This is primarily intended to be useful for projects using Meson wishing
to consume cxxopts as a subproject. By hosting the files upstream users
get the benefit of automatic parity with the CMake based install
provided by an OS vendor or distribution.

The implementation attempts to mirror the CMake build as much as
possible, with the exception of generating the cmake-config files, which
Meson doesn't currently support. It uses a small python script to parse
the cxxopts.hpp header to extract the version, due to a concious design
decision of Meson to leave such complex logic to external scripting
languages like Python.

* CI: add basic Meson testing

I've tried to be a bit more minimal here than the CMake tests are, since
there's already a good cross section of testing there. For Meson, I just
want to touch test each of the major platforms to ensure that it works
2026-01-12 18:00:29 +11:00
Victor Proon 5e6d1e29f7
fix the issue with default empty vectors behaviour. update unit test (#460) 2025-07-18 07:09:03 +10:00
Vitaly dbf4c6a668
Added compatibility with CMake 4. (#451) 2025-03-17 17:46:27 +11:00
Yuxuan Sun 573ec27d72
fix(test): make test C++ standard consistent with build config (#450) 2025-02-27 07:26:25 +11:00
Nigel Stewart 7795b6a47b
C++17 std::filesystem::path support added (#447) 2025-01-14 17:56:41 +11:00
Nigel Stewart f029892dab
C++17 std::optional test coverage fixups (#446) 2024-12-23 07:53:42 +11:00
levonwaveye 10a7a64779
Add ParseResult::contains method (#440) 2024-10-24 07:14:32 +11:00
Jarryd Beck 2ad116a9d3 Update catch header
Fixes #435. Updates catch header to fix include error on MacOS.
2024-07-16 09:29:45 +10:00
權少 59656709c0
Fix example and test compiled warnings and error in MSVC. (#428)
* Fix example and test compiled warnings and error in MSVC.
2024-04-27 12:11:52 +10:00
Nigel Stewart 70fb4e4814
Extend cxxopts API to support as_optional in addition to as query of values (#421)
Co-authored-by: Nigel Stewart <nigel.stewart@emesent.io>
2024-02-29 20:27:19 +11:00
jarro2783 1e175bc1db
Fix ordering of parse_value functions (#420)
Fixes #419. Put the definitions of parse_value functions before they
are called so that the right ones are chosen.
2024-02-20 19:38:44 +11:00
ololuki e84ab5f67c
Fix overflow error in integer_parser. (#417)
Fixes #290.
Checking for overflow should be done before integer overflows.
There are two checks:
(result > limit / base) is used for limits greater than rounded up to base,
e.g. for 65535 it will activate for 65540 and higher.
(result * base > limit - digit) is used for limit+1 to limit+n below
next base rounded number, e.g. 65536 up to 65539.
2024-02-01 16:51:32 +11:00
Jarryd Beck 7bf29108d5 Update catch2 to latest 2.x 2024-01-15 21:04:41 +11:00
Alexander Galanin ddc695ebac
Don't split by list delimiter in positional lists (#398) 2023-06-15 07:34:26 +10:00
Nathaniel Brough 58daccc945
feat(fuzzer): Adds fuzz tests (#386) 2023-02-06 07:30:51 +11:00
Jarryd Beck 4a3d4dbfe0 Fixes #362.
Fix comparing iterators from a different container.
2023-02-01 06:56:03 +11:00
Jarryd Beck 32afbc6526 Fix default bool values
Fixes #382. Keep boolean values when parsing into a reference.
2022-12-15 07:08:03 +11:00
Sourabh Mehta 1dcb44e79a
Fix an additional space in help generated (#377) 2022-11-10 07:24:19 +11:00
Ryan Leary 2e3c6991d3
add . as valid char in option names (#358) 2022-09-29 07:11:32 +10:00
jarro2783 a10bd5233b
Fix values attached to short options (#360)
Fixes #357.
2022-08-13 07:51:41 +10:00
Eyal Rozenberg e976f964c3
Fix issue #240: Multiple long option names / aliases (#349)
* Fixes #240: Multiple long option names / aliases

* We now use a vector of long option names instead of a single name
* When specifying an option, you can provide multiple names separated by commas, at most one of which may have a length of 1 (not necessarily the first specified name). The length-1 name is the single-hyphen switch (the "short name").
* Hashing uses the first long name
* Option help currently only uses the first long name.
2022-07-14 16:42:18 +10:00
Eyal Rozenberg 628dc9202b
Fixes #345, fixes #346: Exception code tweaks (#347)
* Fixes #345, fixes #346, regards #340: Put exceptions in a sub-namespace and renamed them accordingly.

* Also fixed some "loose ends" regarding namespace indentation which were missing in PR #350.

* Dropped `required_option_missing` as it is unused.
2022-07-12 19:45:58 +10:00
Long Deng c59e0c132c
Solve arguments() showing empty keys when only short-only option exists (#318)
* Solve `arguments()` showing empty keys when there is only a short option.
2022-05-11 17:44:25 +10:00
Yannic Staudt 779c429b0e
Added instructions to use cxxopts with tipi to INSTALL (#325) 2022-03-22 22:01:25 +11:00
Jarryd Beck 4e208b95b7 Add a program function
Fixes 323. Adds a function to retrieve the program name.
2022-01-14 16:26:48 +11:00
Jarryd Beck c74846a891 Fix short options adding into unmatched
Fixes #312.
2021-10-21 08:06:53 +11:00
Jarryd Beck c641241a87 Fixes to #204. 2021-10-09 17:02:27 +11:00
Baojun Wang 4b7fccb5f2 Allow empty string to be valid positional arguments
Fixes #204.
2021-10-09 17:02:27 +11:00
RonxBulld 97a4d5511f
Support options like `-j5`. (#286)
* Support option value being attached after the option without a space in between. e.g. -j5
2021-05-06 08:46:40 +10:00
jpr89 c55726ee29
Cmake Revamp (#270)
* Cmake Revamp

I needed to do a variety of things to ensure cxxopts worked well in my own project.

I created a new cmake module to abstract a lot of the logic in the main CMakelists.txt, I think it really assists in the readability of the project. Consequently a lot of logic is now written in functions.

I made a lot of the project options off by default unless the project is being built standalone. As a frequent consumer of cmake libraries this is a huge issue. Since examples, tests, installation, etc. aren't things I expect/desired by default when using libraries.

Co-authored-by: Juan Ramos <juanr0911@gmail.com>
2021-01-17 12:11:02 +11:00
Daniel Lemire 12e496da3d
Making sure that the library can compile without warnings even when crazy pedantic flags are set (#238)
Makes some fixes to satisfy various strict warnings.
2020-10-06 17:06:33 +11:00
jarro2783 3ef9fddc7b
Fix passing a const array to parse (#258)
Fixes #257. The input array is not modified, so we can declare this as
`char const* const*`.
2020-10-03 20:54:06 +10:00
Jarryd Beck fedf9d7b57 Refactor parser
Major refactor of the parsing code organisation to improve encapsulation
and not modify the input arguments. The returned result no longer has
pointers into the original option specification.
2020-10-01 17:12:03 +10:00
Kjetil Andresen 15e8a74e95
Support 'const char**' arguments in Options::parse (#250)
`cxxopts` doesn't modify the contents of the argv strings. This changes
the parse function to take a reference to a `const char**`.
2020-08-11 08:01:29 +10:00
Eyal Rozenberg 5f43f4cbfe
Fixes #245: Mention the option name when throwing on "no value" (#246)
* Fixes #245:

* Added a new exception type: `option_has_no_value_exception`; throwing it when an option has no value we can cast with `as()`, instead of an `std::domain_error`.
* The `OptionValue` type now holds a pointer to the long option name (in its corresponding key within ParseResults's `m_results` field.
2020-07-23 17:27:04 +10:00
Jarryd Beck 23f56e2614 Fix conversion warning in test 2019-11-28 08:32:54 +11:00
Jarryd Beck fce82fb035 Fix duplicate default option
Fixes #197. Don't parse default options twice when there is a short and
long option.
2019-08-08 08:21:52 +10:00
Bartek 3c73d91c0b add_options variant with initializer list (#189)
Allow adding options with a single initializer list.
2019-06-28 08:39:37 +10:00
Jean-Baptiste Bayle 6b6af4f561 Add a method to remove the implicit value of an option (#178) 2019-06-18 17:49:15 +10:00
Christian Lang 7b14d5f60b Fix parsing of std::vector and add test, example and documentation (#182)
Improve parsing into std::vector so that a single argument can take a list.
2019-06-18 08:14:18 +10:00
Jarryd Beck e17c6b0827 Fix integer parsing again 2019-06-14 18:20:22 +10:00
Jean-Baptiste Bayle bd20573829 Parse 0 and 1 into booleans (#177)
* Parse 1 as "true" and 0 as "false" for boolean options.
2019-05-28 17:25:54 +10:00
Jarryd Beck d58271c5fd Allow invalid short option syntax
Fixes #171. Allows invalid syntax for short options to be ignored.
2019-05-28 08:21:36 +10:00
Jarryd Beck d31492e2cd Catch exception using reference 2019-05-02 17:32:48 +10:00
Jarryd Beck 5da5d67111 Throw exception on invalid positional argument
Fixes #169. It seems reasonable to throw an exception when an attempt is
made to parse into positional parameters that don't exist.
2019-05-01 18:34:29 +10:00
Jean Guyomarc'h 51f9a94c91 Fix invalid exception type in catch (#149)
g++ 8.2.0 refuses to compile the test suite because of polymorphic types
that are caught by value. They shall be caught by reference instead.
2018-11-20 08:06:18 +11:00