Commit Graph

413 Commits

Author SHA1 Message Date
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
le-migou
48e265dc4b Remove u8 prefix in string literals. (#172)
String literals with the prefix `u8` now have the type `const char8_t[N]` in
C++20. As a consequence the library does not compile in c++2a mode with GCC
(you can't concatenate `std::basic_string<char>` and `const char8_t[]` as
`char` and `char8_t` are different types).
2019-04-15 18:26:43 +10:00
Jarryd Beck
3876c09072 Use reference instead of value
Fixes #166.
2019-02-19 18:14:36 +11:00
linus-sherrill
9990f73845 Remove empty string initializer. (#159)
The empty string caused the vector to have one element which caused
the test at line 2041 to always fail.
2019-01-14 08:46:41 +11:00
Jarryd Beck
3d405ef163 Improve boolean readme
Fixes #157. Fix the wording in the README about booleans.
2019-01-02 08:47:17 +11:00
Michael Tesch
0edf37b6cc accept single '-' as argument, such as in cat - (#153) 2018-12-20 07:58:37 +11:00
舒俊杰
5950d78558 fix min/max defined macros (#152)
Windows is broken and defines `min` and `max` as a macro, adding parentheses stops them from being expanded.
2018-12-20 07:57:22 +11:00
Jarryd Beck
287d1e39e0 Add to changelog for exception fix 2018-11-20 08:25:24 +11: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
Jarryd Beck
84feb4bd87 Throw in ParseResult::as when option isn't present
Fixes #124.
2018-11-19 17:45:51 +11:00
Jarryd Beck
c713b44d92 Use a shared pointer for the options map
Fixes #132. Since the map of options is shared between Options and
ParseResult, they should use a shared pointer instead of a reference so
that ParseResult can be returned without referencing destroyed memory.
2018-11-08 18:22:42 +11:00
Jarryd Beck
b528324107 Fix option matching 2018-11-08 08:18:54 +11:00
Jarryd Beck
cd65c459ec Build the tests by default.
Fixes #143. There is no reason to make the tests optional.
2018-11-07 18:52:40 +11:00
Jarryd Beck
963c5d0494 Add instructions for running the tests 2018-10-30 08:02:32 +11:00
Mario Werner
320d7a3d1a fixed version parsing in the CMake code (#128) 2018-10-29 18:51:26 +11:00
Jarryd Beck
299750a35d Make INSTALL a bit more clearer 2018-10-29 18:13:14 +11:00
Jarryd Beck
3f2d705302 Improve build and test instructions 2018-10-29 08:47:49 +11:00
parkertomatoes
f75feab968 Handle newlines in description (#138) 2018-10-08 11:57:33 +11:00
Jan Koßmann
1f7ac82495 Fix std::forward return in toLocalString (#134) 2018-09-27 11:28:07 +10:00
Jarryd Beck
7c468aaf68 Allow iterator inputs to parse_positional 2018-08-07 08:00:41 +10:00
Jarryd Beck
95a48de820 Remove unused get_option
Fixes #121. Removes the unused `ParseResult::get_option`.
2018-08-03 08:46:48 +10:00
Jarryd Beck
cde83be99b Fix version numbering in CMakeLists.txt
Fixes #115. Read the version number out of `cxxopts.hpp` instead of
having to duplicate it in CMakeLists.txt.
2018-07-05 17:55:51 +10:00
Jarryd Beck
e725ea3084 Use unsigned type for integer digit
Fixes #109. Although we always used numbers in the ASCII range, it was
in a `size_t`, leading to a warning about possible loss of data on some
compilers.
2018-05-08 07:59:17 +10:00
Jarryd Beck
d47101a101 Allow leading zeroes in integers
Fixes #101. Allows leading zeroes in the integer parser.
2018-05-07 18:46:26 +10:00
Frank Schoenmann
ca6e9f70eb Allow unrecognised options. (#105)
Allows unrecognised options to be left alone by the parser without throwing an exception.
2018-04-12 08:15:07 +10:00
Jarryd Beck
00e8ecc482 Add a readme comment about versions 2018-04-12 08:14:07 +10:00
Jarryd Beck
a3ccf3e1f7 Add revert to changelog 2018-04-10 08:50:17 +10:00
Jarryd Beck
cc4914f065 Revert "Added const to argv type for better interoperability. (#99)"
This reverts commit 0f819a5cab.
2018-04-10 08:48:08 +10:00
Jarryd Beck
0fe1dc892b Prepare changelog for release 2018-04-09 08:17:56 +10:00
Jarryd Beck
16e3968e1a update readme 2018-03-21 18:14:09 +11:00
Jesús González
0f819a5cab Added const to argv type for better interoperability. (#99)
* Added const to argv type for better interoperability.
2018-03-09 08:07:29 +11:00
Jarryd Beck
e40645e084 Don't show default when boolean false
Fixes #102. Don't show the default value when it is a boolean and the
value is false. Note that this is a bit of a hack and the
implementation should probably be reevaluated in the future.
2018-03-08 08:53:26 +11:00
Jarryd Beck
76bd60dc17 Add support for std::optional
Fixes #93. This adds C++17 only support for `std::optional` values for
command line parameters.
2018-01-31 18:25:52 +11:00
Jarryd Beck
e792760ab9 Changes default values so that they aren't counted
Fixes #96. Default values of options not specified on the command line
had a `count` of 1. It would be better if they had a count of 0 because
they were not actually specified, so that count is only for options
given by the user.
2018-01-30 18:55:49 +11:00
Jesús González
76717cb3dd Add default "default" value to boolean options (#94)
* Add default "default" value of "false" to boolean options, therefore allowing to call result["boolOpt"].as<bool>() without throwing an exception.
2018-01-17 07:55:45 +11:00
Jarryd Beck
24162899c9 fix some types 2017-12-15 17:43:31 +11:00
Addy
ec7db35ac6 fixed “possible loss of data” warning on Visual Studio (#89) 2017-12-15 08:02:02 +11:00
Jarryd Beck
c69ca9166d version bump 2017-12-06 18:28:32 +11:00
Jarryd Beck
9c2e41a4e2 add clang back to travis 2017-12-04 18:14:40 +11:00
Masashi Fujita
ec9e62c2c8 | should be inside of (…) (#87)
* `|` should be inside of `(…)`

It's possible to use `(t|true|T|True)` as `truthy_pattern` but still failing `true` as a truthy under my environment :-(

```
Apple LLVM version 8.0.0 (clang-800.0.42.1)
Target: x86_64-apple-darwin15.6.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
```
2017-12-04 18:15:20 +11:00
Jarryd Beck
fab3bae2ff Clarify ParseResult being in scope 2017-12-01 07:58:15 +11:00
Jarryd Beck
346956eff1 Fix overly strict shadows in GCC 4.9
Fixes #86. Rename some variables so that the overly strict shadows warning
on GCC 4.9 is not triggered.
2017-11-30 08:45:00 +11:00
Jarryd Beck
2015a7438a Add GCC 4.9 to travis build 2017-11-30 08:39:58 +11:00
Jarryd Beck
5b774d7a7e Allow help string to be customised
Fixes #82. This allows the help string after the program name to be
completely replaced by the user.
2017-11-28 18:07:23 +11:00
Jarryd Beck
2ca68adeaf Fix positional arguments overload
Fixes #83.

Adds an overload for positional arguments taking a
`std::initializer_list`. When using an `initializer_list` with one
argument, the function call is ambiguous matching both `std::string`
and `std::vector<std::string>`.
2017-11-28 18:01:41 +11:00
Jarryd Beck
abe9ebd6b4 Fix handling of implicit values
Fixes #84. Implicit values are not handled very well. For example:

    --foo false true
    --foo --bar

In the first, `false` is an argument to `--foo`, and then `true` is a
positional argument. In the second, because of the hyphen in `--bar`, `--foo`
is parsed with its implicit value. This seems inconsistent and unintuitive.

Better is that implicit values *never* consume the next parameter to be
completely consistent. This means that values with an implicit parameter
*must* be specified using the `--option=value` form.
2017-11-28 08:43:55 +11:00
Jarryd Beck
0a49b82072 add a test for broken boolean options
The parsing for boolean options was broken by 6c9bae4a07 which added implicit
and default values, and the ability to parse boolean strings. Having an option
after the boolean tried to parse that into the boolean instead of as a
positional parameter.

See #84 for the bug report.
2017-11-27 08:36:34 +11:00
Jarryd Beck
92779bef66 Remove clang for now
It appears that the `libc++` available on Ubuntu 14.04 is broken and
doesn't handle the boolean regex correctly. Newer versions appear to be
correct but I have to work out how to get 14.04 to use it.
2017-11-27 08:33:46 +11:00
Jarryd Beck
8893afe13c Merge branch '2_0' 2017-11-15 18:04:20 +11:00