Commit Graph

102 Commits

Author SHA1 Message Date
Pranav Srinivas Kumar
281f1ab017 Closes #113, add custom std::ostream& argument to ArgumentParser constructor 2023-11-04 09:31:13 -05:00
Pranav Srinivas Kumar
7a3e0f1cb3 Added another unit test for optional argument error reporting 2023-11-04 09:17:59 -05:00
Pranav Srinivas Kumar
62052fefcb Closes #285 2023-11-04 09:01:31 -05:00
Pranav Srinivas Kumar
7657a22001 Updated formatting of error message, showing all variations of argument name 2023-11-03 22:18:08 -05:00
Pranav Srinivas Kumar
78ba5e9828 Removed brackets and quotes in error message 2023-11-03 22:12:00 -05:00
Pranav Srinivas Kumar
4111905a74 Improved error reporting for #299 2023-11-03 22:05:46 -05:00
Pranav Srinivas Kumar
716ec60291 Added flag() shorthand function 2023-10-27 16:37:20 -05:00
Pranav Srinivas Kumar
5e7ce61ca7 Closes #278 2023-10-27 12:59:04 -05:00
Pranav Srinivas Kumar
d28188f4d5 Closes #247 2023-10-27 12:34:57 -05:00
Pranav Srinivas Kumar
bf9642c51d Upgraded doctest to v2.4.11 2023-10-27 11:41:35 -05:00
Pranav Srinivas Kumar
0b8d0e2426 Added support for integer type in choices 2023-10-27 10:28:54 -05:00
Pranav Srinivas Kumar
9bb553b882 #277 Added in-built support for string_type choices 2023-10-27 09:16:25 -05:00
Christoph Hindermann
6c4bddb990 CMakefile: Use -Wpedantic, -Werror and -Wextra for compilation in gcc. Fixed warnings 2023-10-20 19:57:12 +02:00
Pranav
57b63b09fa
Merge pull request #290 from Arthapz/master
Add C++20 module
2023-10-20 08:06:14 -05:00
Kian-Meng Ang
aa25a2f3ac Fix typos
Found via `codespell -L seh`
2023-10-19 13:09:11 +08:00
Arthur LAURENT
6723c81877
update test to use module when WITH_MODULE macro is set 2023-10-15 18:51:56 +02:00
Pranav
b0930ab028
Merge pull request #268 from fanurs/align_multiline_message
Fix issue #248: Align multiline help messages
2023-07-11 08:15:12 -05:00
Fanurs
e82653c2d9 Fixed test for multiline help message alignment 2023-04-22 19:23:17 -04:00
Fanurs
19d85eadb0 Passed test for multiline help message alignment 2023-04-22 15:16:47 -04:00
Sean Robinson
0ae3c7d919 Add exit_on_default_arguments parameter to ArgumentParser
Allows users to opt-out of std::exit call in default arguments without
needing to replace with new --help and --version arguments.

Signed-off-by: Sean Robinson <sean.robinson@scottsdalecc.edu>
2023-03-22 09:07:45 -07:00
Pranav
e516556733
Merge pull request #254 from skrobinson/fix-maintenance
Various maintenance tasks
2023-02-19 10:29:59 -06:00
Sean Robinson
7ed952f4fe Add test for ArgumentParser::get() with inappropriate type
Signed-off-by: Sean Robinson <sean.robinson@scottsdalecc.edu>
2023-01-17 13:57:59 -07:00
Sean Robinson
cb3da173f6 Fix crash with char[] default values
Closes #249

Reported-by: @pfeatherstone
Signed-off-by: Sean Robinson <sean.robinson@scottsdalecc.edu>
2023-01-05 13:02:40 -07:00
Sean Robinson
5f22faa973 Add ArgumentParser::at to retrieve arguments and subparsers
This allows updating attached object properties without holding external
references to the various Argument and ArgumentParser objects.

Closes #227

Signed-off-by: Sean Robinson <sean.robinson@scottsdalecc.edu>
2022-11-29 13:43:16 -07:00
Sergey Podobry
8e6a36dd0d Add is_subcommand_used overload
It's useful for removing string literals duplication in a code.
2022-11-08 01:31:45 +02:00
Sean Robinson
f710bbdacf Add operator bool for ArgumentParser
This allows checking whether user input was processed into the parser
or any attached subparsers.

Closes #212

Signed-off-by: Sean Robinson <sean.robinson@scottsdalecc.edu>
2022-10-10 15:26:42 -07:00
Sean Robinson
2a15178bb7 Include canonical argument name in nargs range validation error
The name of a positional argument is never used.

Closes #208

Signed-off-by: Sean Robinson <sean.robinson@scottsdalecc.edu>
2022-09-23 07:54:58 -07:00
Pranav Srinivas Kumar
05232b7487 Started adding samples 2022-09-21 18:09:25 -07:00
Pranav Srinivas Kumar
66730967aa Added support for custom prefix characters #67 2022-09-21 09:48:48 -07:00
Pranav Srinivas Kumar
616062e2bf Added -Wshadow and -Wconversion to CXX_FLAGS and fixed warnings 2022-09-21 07:43:46 -07:00
Pranav Srinivas Kumar
6dd2a3cf4b Added example to README for option=value support 2022-09-21 07:23:02 -07:00
Pranav Srinivas Kumar
20095a697a Added option=value support using #185 2022-09-21 06:54:34 -07:00
Pranav Srinivas Kumar
14287af007 Closes #94 2022-09-21 06:23:42 -07:00
Pranav Srinivas Kumar
6e23d5b22e Closes #181 2022-09-21 05:47:47 -07:00
Pranav Srinivas Kumar
793fbcde16 Added is_subcommand_used helper function 2022-09-20 21:15:58 -07:00
Pranav Srinivas Kumar
6c7da857b6 Added table of contents to README and clang formatted code 2022-09-20 20:27:24 -07:00
Pranav Srinivas Kumar
2f2858a8a7 Draft implementation of subparsers #42 2022-09-20 19:54:29 -07:00
Yoshihiro Hokazono
7b5084c454 Fix a typo 2022-06-22 07:16:41 +09:00
Yoshihiro Hokazono
b869b5a209 NArgsPattern -> nargs_pattern (to snake case) 2022-06-22 07:07:59 +09:00
Yoshihiro Hokazono
08943f47ab Merge branch 'master' into feature/variable-length-nargs 2022-06-21 08:36:33 +09:00
Yoshihiro Hokazono
12fcae66a7 Prefer pre-const to post-const 2022-06-21 06:48:13 +09:00
Yoshihiro Hokazono
6dfaa1c20c Restore a "remaining" test case for compat 2022-06-21 06:44:29 +09:00
Ameya Vikram Singh
f56aec307f Updates doctest from v2.3.5 to v2.4.8
Fixes the build error on latest GNU/Linux Systems: (https://github.com/doctest/doctest/issues/473)

Signed-off-by: Ameya Vikram Singh <ameya.v.singh@gmail.com>
2022-04-16 20:35:37 +05:30
Sean Robinson
97204363b5 Refactor configuration for StaticAnalysis
Upstream StaticAnalysis looks to be changing for more flexibility with
source files to process.  While these changes may eventually benefit
argparse, the public interfaces are in flux and we need a stable tool.
argparse also needs a SA change which is not yet upstream.

Trying to run clang-tidy via StaticAnalysis on a single file in a
directory with many source file is not easy, so move the analysis kernel
to a location (i.e. tools) where it is the only C++ source file.

Another benefit is cppcheck no longer needs to be told to ignore the test
sources.

Signed-off-by: Sean Robinson <sean.robinson@scottsdalecc.edu>
2022-02-07 11:51:22 -07:00
Sean Robinson
18a229e849 Add a minimal binary to generate compile_commands.json file
clang-tidy needs compile_commands.json to generate a set of source files
to parse.  tidy-base is not built but is used as a source file in which
included headers can be parsed.  Without this process, clang-tidy will
process many other source files (e.g. doctest.hpp) that we do not want
to worry about.

Signed-off-by: Sean Robinson <sean.robinson@scottsdalecc.edu>
2021-11-10 13:54:25 -07:00
Maciej Patro
87afaba6ba Improve thrown message in case of invalid argument.
Now message contains information which argument is the source of error.
It's easier to spot typo/understand which part of more complex command
is the source of problem.
2021-11-05 09:56:17 +01:00
Sean Robinson
ea1f7ef663 Allow removal of default arguments (i.e. --help and --version)
The help and version arguments are still included by default, but which
default arguments to include can be overridden at ArgumentParser creation.

argparse generally copies Python argparse behavior.  This includes a
default `--help`/`-h` argument to print a help message and exit.  Some
developers using argparse find the automatic exit to be undesirable.

The Python argparse has an opt-out parameter when constructing an
ArgumentParser.  Using `add_help=False` avoids adding a default `--help`
argument and allows the developer to implement a custom help.

This commit adds a similar opt-out to our C++ argparse, but keeps the
current behavior as the default.  The `--help`/`-h` and `--version`/`-v`
Arguments handle their own output and exit rather than specially treating
them in ArgumentParser::parse_args_internal.

Closes #119
Closes #138
Closes #139

Signed-off-by: Sean Robinson <sean.robinson@scottsdalecc.edu>
2021-10-27 09:02:33 -07:00
Sean Robinson
2b05334a3c Run Argumnet::action functor for zero-parameter arguments
Previously, only arguments with one or more parameters would run actions.
But, at times it can be useful to run an action when an argument does not
expect any parameters.

Closes #104

Signed-off-by: Sean Robinson <sean.robinson@scottsdalecc.edu>
2021-10-27 09:02:33 -07:00
Sean Robinson
af6bbc1d47 Skip --version test until it can be made to work
Because program.parse_args( { "test", "--version" }) calls std::exit(0),
the REQUIRE line never runs and this test is less useful.  Because tests
execution stops here, the doctest status report is not output.  If
--version can be made to not exit during this test, then the test could
be restored.

Signed-off-by: Sean Robinson <sean.robinson@scottsdalecc.edu>
2021-10-27 07:33:22 -07:00
Yoshihiro Hokazono
bec93acaa7 Avoid use ALL_CAPS for enumerators 2021-09-16 08:01:26 +09:00