argparse/test
Even Rouault 8f5b3e0722
Several bug fixes in usage, and improvement in usage and help
- Display mutually exclusive arguments as ``[[-a]|[-b]]`` in usage
- Add ... trailer to repeatable arguments in usage: ``[-x]...``

- Implement the following enhancements:

By default usage is reported on a single line.

The ``ArgumentParser::set_usage_max_line_width(width)`` method can be used
to display the usage() on multiple lines, by defining the maximum line width.

It can be combined with a call to ``ArgumentParser::set_usage_break_on_mutex()``
to ask grouped mutually exclusive arguments to be displayed on a separate line.

``ArgumentParser::add_usage_newline()`` can also be used to force the next
argument to be displayed on a new line in the usage output.

The following snippet

```cpp
    argparse::ArgumentParser program("program");
    program.set_usage_max_line_width(80);
    program.set_usage_break_on_mutex();
    program.add_argument("--quite-long-option-name").flag();
    auto &group = program.add_mutually_exclusive_group();
    group.add_argument("-a").flag();
    group.add_argument("-b").flag();
    program.add_argument("-c").flag();
    program.add_argument("--another-one").flag();
    program.add_argument("-d").flag();
    program.add_argument("--yet-another-long-one").flag();
    program.add_argument("--will-go-on-new-line").flag();
    program.add_usage_newline();
    program.add_argument("--new-line").flag();
    std::cout << program.usage() << std::endl;
```

will display:
```console
Usage: program [--help] [--version] [--quite-long-option-name]
               [[-a]|[-b]]
               [-c] [--another-one] [-d] [--yet-another-long-one]
               [--will-go-on-new-line]
               [--new-line]
```

Furthermore arguments can be separated into several groups by calling
``ArgumentParser::add_group(group_name)``. Only optional arguments should
be specified after the first call to add_group().

```cpp
    argparse::ArgumentParser program("program");
    program.set_usage_max_line_width(80);
    program.add_argument("-a").flag().help("help_a");
    program.add_group("Advanced options");
    program.add_argument("-b").flag().help("help_b");
```

will display:
```console
Usage: program [--help] [--version] [-a]

Advanced options:
               [-b]
```
2024-03-13 02:09:44 +01:00
..
.gitignore Renamed directories 2019-04-01 22:01:40 -04:00
argparse_details.cppm update test to use module when WITH_MODULE macro is set 2023-10-15 18:51:56 +02:00
CMakeLists.txt Merge pull request #331 from rouault/store_into 2024-03-12 10:13:31 -04:00
doctest.hpp Upgraded doctest to v2.4.11 2023-10-27 11:41:35 -05:00
main.cpp Annotate test cases with doctest::test_suite 2019-11-21 14:24:50 -06:00
README.md Update README.md 2019-04-01 22:03:59 -04:00
test_actions.cpp update test to use module when WITH_MODULE macro is set 2023-10-15 18:51:56 +02:00
test_append.cpp #277 Added in-built support for string_type choices 2023-10-27 09:16:25 -05:00
test_as_container.cpp #277 Added in-built support for string_type choices 2023-10-27 09:16:25 -05:00
test_bool_operator.cpp #277 Added in-built support for string_type choices 2023-10-27 09:16:25 -05:00
test_choices.cpp Added nargs test for multiple values to a choices() argument 2023-11-13 14:19:55 -08:00
test_compound_arguments.cpp Added flag() shorthand function 2023-10-27 16:37:20 -05:00
test_container_arguments.cpp update test to use module when WITH_MODULE macro is set 2023-10-15 18:51:56 +02:00
test_default_args.cpp #277 Added in-built support for string_type choices 2023-10-27 09:16:25 -05:00
test_default_value.cpp Added flag() shorthand function 2023-10-27 16:37:20 -05:00
test_equals_form.cpp #277 Added in-built support for string_type choices 2023-10-27 09:16:25 -05:00
test_error_reporting.cpp Closes #113, add custom std::ostream& argument to ArgumentParser constructor 2023-11-04 09:31:13 -05:00
test_get.cpp #277 Added in-built support for string_type choices 2023-10-27 09:16:25 -05:00
test_help.cpp Several bug fixes in usage, and improvement in usage and help 2024-03-13 02:09:44 +01:00
test_hidden_alias.cpp Add a ArgumentParser::add_hidden_alias_for() method 2024-03-12 12:08:40 +01:00
test_invalid_arguments.cpp update test to use module when WITH_MODULE macro is set 2023-10-15 18:51:56 +02:00
test_is_used.cpp update test to use module when WITH_MODULE macro is set 2023-10-15 18:51:56 +02:00
test_issue_37.cpp update test to use module when WITH_MODULE macro is set 2023-10-15 18:51:56 +02:00
test_mutually_exclusive_group.cpp Marked copy and move constructors as deleted 2023-11-05 18:13:17 -06:00
test_negative_numbers.cpp update test to use module when WITH_MODULE macro is set 2023-10-15 18:51:56 +02:00
test_optional_arguments.cpp Added flag() shorthand function 2023-10-27 16:37:20 -05:00
test_parent_parsers.cpp update test to use module when WITH_MODULE macro is set 2023-10-15 18:51:56 +02:00
test_parse_args.cpp update test to use module when WITH_MODULE macro is set 2023-10-15 18:51:56 +02:00
test_parse_known_args.cpp #277 Added in-built support for string_type choices 2023-10-27 09:16:25 -05:00
test_positional_arguments.cpp update test to use module when WITH_MODULE macro is set 2023-10-15 18:51:56 +02:00
test_prefix_chars.cpp Added flag() shorthand function 2023-10-27 16:37:20 -05:00
test_repr.cpp #277 Added in-built support for string_type choices 2023-10-27 09:16:25 -05:00
test_required_arguments.cpp update test to use module when WITH_MODULE macro is set 2023-10-15 18:51:56 +02:00
test_scan.cpp Added support for binary notation, e.g., 0b101 2023-11-05 19:06:50 -06:00
test_store_into.cpp Add Argument::store_into() functions 2024-03-12 12:50:22 +01:00
test_stringstream.cpp Closes #113, add custom std::ostream& argument to ArgumentParser constructor 2023-11-04 09:31:13 -05:00
test_subparsers.cpp NEW: suppress flag for subcommand 2023-11-05 15:23:15 +03:00
test_utility.hpp update test to use module when WITH_MODULE macro is set 2023-10-15 18:51:56 +02:00
test_version.cpp update test to use module when WITH_MODULE macro is set 2023-10-15 18:51:56 +02:00

Argparse Tests

Linux

$ mkdir build
$ cd build
$ cmake ../.
$ make
$ ./tests

Windows

  1. Generate Visual Studio solution
$ mkdir build
$ cd build
$ cmake ../. -G "Visual Studio 15 2017"
  1. Open ARGPARSE.sln
  2. Build tests in RELEASE | x64
  3. Run tests.exe