|
12 | 12 | - [Boolean Flags](#boolean-flags) |
13 | 13 | - [Argument Parameters](#argument-parameters) |
14 | 14 | - [Common Parameters](#common-parameters) |
15 | | - - [help](#1-help---the-arguments-description-which-will-be-printed-when-printing-the-parser-class-instance) |
16 | | - - [hidden](#2-hidden---if-this-option-is-set-for-an-argument-then-it-will-not-be-included-in-the-program-description) |
17 | | - - [required](#3-required---if-this-option-is-set-for-an-argument-and-its-value-is-not-passed-in-the-command-line-an-exception-will-be-thrown) |
18 | | - - [bypass required](#4-bypass_required---if-this-option-is-set-for-an-argument-the-required-option-for-other-arguments-will-be-discarded-if-the-bypassing-argument-is-used-in-the-command-line) |
19 | | - - [nargs](#5-nargs---sets-the-allowed-number-of-values-to-be-parsed-for-an-argument) |
20 | | - - [greedy](#6-greedy---if-this-option-is-set-the-argument-will-consume-all-command-line-values-until-its-upper-nargs-bound-is-reached) |
21 | | - - [choices](#7-choices---a-list-of-valid-argument-values) |
22 | | - - [value actions](#8-value-actions---functions-that-are-called-after-parsing-an-arguments-value) |
23 | | - - [default values](#9-default_values---a-list-of-values-which-will-be-used-if-no-values-for-an-argument-have-been-parsed) |
| 15 | + - [help](#1-help---the-arguments-description-which-will-be-printed-when-printing-the-parser-class-instance) - the text shown in the help message to describe an argument |
| 16 | + - [hidden](#2-hidden---if-this-option-is-set-for-an-argument-then-it-will-not-be-included-in-the-program-description) - hides the argument from the generated program description and help output |
| 17 | + - [required](#3-required---if-this-option-is-set-for-an-argument-and-its-value-is-not-passed-in-the-command-line-an-exception-will-be-thrown) - marks the argument as mandatory; not using it will cause an error |
| 18 | + - [suppress arg checks](#4-suppress_arg_checks---using-a-suppressing-argument-results-in-suppressing-requirement-checks-for-other-arguments) - if a suppressing argument is used, other requirement validation will be skipped for other arguments |
| 19 | + - [nargs](#5-nargs---sets-the-allowed-number-of-values-to-be-parsed-for-an-argument) - defines how many values an argument can or must accept |
| 20 | + - [greedy](#6-greedy---if-this-option-is-set-the-argument-will-consume-all-command-line-values-until-its-upper-nargs-bound-is-reached) - makes the argument consume all following values until its limit is reached |
| 21 | + - [choices](#7-choices---a-list-of-valid-argument-values) - restricts the valid inputs to a predefined set of values |
| 22 | + - [value actions](#8-value-actions---functions-that-are-called-after-parsing-an-arguments-value) - allows you to run custom code after the argument’s value is parsed |
| 23 | + - [default values](#9-default_values---a-list-of-values-which-will-be-used-if-no-values-for-an-argument-have-been-parsed) - specifies fallback values to use if none are provided |
24 | 24 | - [Parameters Specific for Optional Arguments](#parameters-specific-for-optional-arguments) |
25 | | - - [on-flag actions](#1-on-flag-actions---functions-that-are-called-immediately-after-parsing-an-arguments-flag) |
26 | | - - [implicit values](#2-implicit_values---a-list-of-values-which-will-be-set-for-an-argument-if-only-its-flag-but-no-values-are-parsed-from-the-command-line) |
| 25 | + - [on-flag actions](#1-on-flag-actions---functions-that-are-called-immediately-after-parsing-an-arguments-flag) - executes custom code immediately when the argument’s flag is present |
| 26 | + - [implicit values](#2-implicit_values---a-list-of-values-which-will-be-set-for-an-argument-if-only-its-flag-but-no-values-are-parsed-from-the-command-line) - automatically assigns a value if an argument flag is used without an explicit value |
27 | 27 | - [Predefined Parameter Values](#predefined-parameter-values) |
28 | 28 | - [Default Arguments](#default-arguments) |
29 | 29 | - [Argument Groups](#argument-groups) |
30 | 30 | - [Creating New Groups](#creating-new-groups) |
31 | 31 | - [Adding Arguments to Groups](#adding-arguments-to-groups) |
32 | 32 | - [Group Attributes](#group-attributes) |
33 | 33 | - [Complete Example](#complete-example) |
| 34 | + - [Suppressing Argument Group Checks](#suppressing-argument-group-checks) |
34 | 35 | - [Parsing Arguments](#parsing-arguments) |
35 | 36 | - [Basic Argument Parsing Rules](#basic-argument-parsing-rules) |
36 | 37 | - [Compound Arguments](#compound-arguments) |
@@ -222,7 +223,7 @@ parser.add_optional_argument("n", ap::n_secondary); |
222 | 223 | > |
223 | 224 | > - The default value type of any argument is `std::string`. |
224 | 225 | > - If the argument's value type is `ap::none_type`, the argument will not accept any values and therefore no value-related parameters can be set for such argument. This includes: |
225 | | -> - [nargs](#5-nargs---sets-the-allowed-number-of-values-to-be-parsed-for-an-argument-this-can-be-set-as-a) |
| 226 | +> - [nargs](#5-nargs---sets-the-allowed-number-of-values-to-be-parsed-for-an-argument) |
226 | 227 | > - [greedy](#6-greedy---if-this-option-is-set-the-argument-will-consume-all-command-line-values-until-its-upper-nargs-bound-is-reached) |
227 | 228 | > - [choices](#7-choices---a-list-of-valid-argument-values) |
228 | 229 | > - [value actions](#8-value-actions---functions-that-are-called-after-parsing-an-arguments-value) |
@@ -318,9 +319,7 @@ Optional arguments: |
318 | 319 | > [!WARNING] |
319 | 320 | > |
320 | 321 | > - If a positional argument is defined as non-required, then no required positional argument can be defined after (only other non-required positional arguments and optional arguments will be allowed). |
321 | | -> - For both positional and optional arguments: |
322 | | -> - enabling the `required` option disables the `bypass_required` option |
323 | | -> - disabling the `required` option has no effect on the `bypass_required` option. |
| 322 | +> - If an argument is suppressing (see [suppress arg checks](#4-suppress_arg_checks---using-a-suppressing-argument-results-in-suppressing-requirement-checks-for-other-arguments) and [Suppressing Argument Group Checks](#suppressing-argument-group-checks)), then it cannot be required (an exception will be thrown). |
324 | 323 |
|
325 | 324 | ```cpp |
326 | 325 | // example: positional arguments |
@@ -377,24 +376,27 @@ Command Result |
377 | 376 |
|
378 | 377 | <br /> |
379 | 378 |
|
380 | | -#### 4. `bypass_required` - If this option is set for an argument, the `required` option for other arguments will be discarded if the bypassing argument is used in the command-line. |
| 379 | +#### 4. `suppress_arg_checks` - Using a suppressing argument results in suppressing requirement checks for other arguments. |
| 380 | + |
| 381 | +If an argument is defined with the `suppress_arg_checks` option enabled and such argument is explicitly used in the command-line, then requirement validation will be suppressed/skipped for other arguments. This includes validating whether: |
| 382 | +- a required argument has been parsed |
| 383 | +- the number of values parsed for an argument matches the specified [nargs](#5-nargs---sets-the-allowed-number-of-values-to-be-parsed-for-an-argument) range. |
381 | 384 |
|
382 | 385 | > [!NOTE] |
383 | 386 | > |
384 | | -> - Both all arguments have the `bypass_required` option disabled. |
385 | | -> - The default value of the value parameter of the `argument::bypass_required(bool)` method is `true` for all arguments. |
| 387 | +> - All arguments have the `suppress_arg_checks` option disabled by default. |
| 388 | +> - The default value of the value parameter of the `argument::suppress_arg_checks(bool)` method is `true` for all arguments. |
386 | 389 |
|
387 | 390 | > [!WARNING] |
388 | 391 | > |
389 | | -> For both positional and optional arguments: |
390 | | -> - enabling the `bypass_required` option disables the `required` option |
391 | | -> - disabling the `bypass_required` option has no effect on the `required` option. |
| 392 | +> - Enabling the `suppress_arg_checks` option has no effect on [argument group](#argument-groups) requirements validation. |
| 393 | +> - Enabling argument checks suppressing is not possible for required arguments (an exception will be thrown). |
392 | 394 |
|
393 | 395 | ```cpp |
394 | 396 | // example: optional arguments |
395 | 397 | parser.add_positional_argument("input"); |
396 | 398 | parser.add_optional_argument("output", "o").required(); |
397 | | -parser.add_optional_argument("version", "v").bypass_required(); |
| 399 | +parser.add_optional_argument("version", "v").suppress_arg_checks(); |
398 | 400 |
|
399 | 401 | parser.parse_args(argc, argv); |
400 | 402 |
|
@@ -522,7 +524,7 @@ Actions are represented as functions, which take the argument's value as an argu |
522 | 524 | ```cpp |
523 | 525 | void is_valid_user_tag(const std::string& tag) { |
524 | 526 | if (tag.empty() or tag.front() != '@') |
525 | | - throw std::runtime_error(std::format("Invalid user tag: `{}` — must start with '@'", tag)); |
| 527 | + throw std::runtime_error(std::format("Invalid user tag: `{}` - must start with '@'", tag)); |
526 | 528 | } |
527 | 529 |
|
528 | 530 | parser.add_optional_argument<std::string>("user", "u") |
@@ -834,15 +836,16 @@ parser.default_arguments(<args>); |
834 | 836 |
|
835 | 837 | ## Argument Groups |
836 | 838 |
|
837 | | -Argument groups provide a way to organize related optional arguments into logical sections. They make the command-line interface easier to read in help messages, and can enforce rules such as **mutual exclusivity** or **required usage**. |
| 839 | +Argument groups provide a way to organize related arguments into logical sections and enforce group-wise requirements. |
838 | 840 |
|
839 | 841 | By default, every parser comes with two predefined groups: |
840 | 842 |
|
841 | 843 | - **Positional Arguments** – contains all arguments added via `add_positional_argument`. |
842 | 844 | - **Optional Arguments** – contains all arguments added via `add_optional_argument` or `add_flag` without explicitly specifying an argument group. |
843 | 845 |
|
844 | | -User-defined groups can only contain optional arguments (including flags). This allows you to structure your command-line interface into meaningful sections such as "Input Options", "Output Options", or "Debug Settings". |
845 | | -
|
| 846 | +> [!NOTE] |
| 847 | +> |
| 848 | +> All predefined arguments are bound to one of the predefined groups. |
846 | 849 |
|
847 | 850 | ### Creating New Groups |
848 | 851 |
|
@@ -934,6 +937,26 @@ Output Options: (required, mutually exclusive) |
934 | 937 | --print, -p : Print output to the console |
935 | 938 | ``` |
936 | 939 |
|
| 940 | +### Suppressing Argument Group Checks |
| 941 | +
|
| 942 | +Similarly to [suppressing argument checks](#4-suppress_arg_checks---using-a-suppressing-argument-results-in-suppressing-requirement-checks-for-other-arguments), an argument can suppress the requirement checks of argument groups: |
| 943 | +
|
| 944 | +```c++ |
| 945 | +argument.suppress_group_checks(); |
| 946 | +``` |
| 947 | +
|
| 948 | +If such argument is used the requirement checks associated with the [group attributes](#group-attributes) will not be validated. |
| 949 | +
|
| 950 | +> [!NOTE] |
| 951 | +> |
| 952 | +> - All arguments have the `suppress_group_checks` option disabled by default. |
| 953 | +> - The default value of the value parameter of the `argument::suppress_group_checks(bool)` method is `true` for all arguments. |
| 954 | +
|
| 955 | +> [!WARNING] |
| 956 | +> |
| 957 | +> - Enabling the `suppress_group_checks` option has no effect on argument requirements validation. |
| 958 | +> - Enabling argument group checks suppressing is not possible for required arguments (an exception will be thrown). |
| 959 | +
|
937 | 960 | <br/> |
938 | 961 | <br/> |
939 | 962 | <br/> |
|
0 commit comments