You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/tutorial.md
+30-25Lines changed: 30 additions & 25 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -12,19 +12,20 @@
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) - 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
15
+
-[Help - The argument's description which will be printed when printing the parser class instance.](#help---the-arguments-description-which-will-be-printed-when-printing-the-parser-class-instance)
16
+
-[Hidden - If this option is set for an argument, then it will not be included in the program description.](#hidden---if-this-option-is-set-for-an-argument-then-it-will-not-be-included-in-the-program-description)
17
+
-[Required - If this option is set for an argument and it's value is not passed in the command-line, an exception will be thrown.](#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
+
-[Argument Checks Suppression - Using a suppressing argument results in suppressing requirement checks for other arguments.](#argument-checks-suppression---using-a-suppressing-argument-results-in-suppressing-requirement-checks-for-other-arguments)
19
+
-[Number of Arguments - Sets the allowed number of values to be parsed for an argument.](#number-of-arguments---sets-the-allowed-number-of-values-to-be-parsed-for-an-argument)
20
+
-[Greedy Parsing - If this option is set, the argument will consume ALL command-line values until it's upper nargs bound is reached.](#greedy-parsing---if-this-option-is-set-the-argument-will-consume-all-command-line-values-until-its-upper-nargs-bound-is-reached)
21
+
-[Choices - A list of valid argument values.](#choices---a-list-of-valid-argument-values)
22
+
-[Value Actions - Functions that are called after parsing an argument's value.](#value-actions---functions-that-are-called-after-parsing-an-arguments-value)
23
+
-[Default Values - A list of values which will be used if no values for an argument have been parsed](#default-values---a-list-of-values-which-will-be-used-if-no-values-for-an-argument-have-been-parsed)
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) - 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
25
+
-[On-flag Actions - Functions that are called immediately after parsing an argument's flag.](#on-flag-actions---functions-that-are-called-immediately-after-parsing-an-arguments-flag)
26
+
-[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.](#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)
#### 2. `hidden` - If this option is set for an argument, then it will not be included in the program description.
286
+
#### Hidden - If this option is set for an argument, then it will not be included in the program description.
282
287
283
288
By default all arguments are visible, but this can be modified using the `hidden(bool)` setter as follows:
284
289
@@ -309,7 +314,7 @@ Optional arguments:
309
314
310
315
<br />
311
316
312
-
#### 3. `required` - If this option is set for an argument and it's value is not passed in the command-line, an exception will be thrown.
317
+
#### Required - If this option is set for an argument and it's value is not passed in the command-line, an exception will be thrown.
313
318
314
319
> [!IMPORTANT]
315
320
>
@@ -376,7 +381,7 @@ Command Result
376
381
377
382
<br />
378
383
379
-
#### 4. `suppress_arg_checks` - Using a suppressing argument results in suppressing requirement checks for other arguments.
384
+
#### Argument Checks Suppression - Using a suppressing argument results in suppressing requirement checks for other arguments.
380
385
381
386
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
387
- a required argument has been parsed
@@ -417,7 +422,7 @@ os << data << std::endl;
417
422
418
423
<br />
419
424
420
-
#### 5. `nargs` - Sets the allowed number of values to be parsed for an argument.
425
+
#### Number of Arguments - Sets the allowed number of values to be parsed for an argument.
421
426
422
427
The `nargs` parameter can be set as:
423
428
@@ -458,7 +463,7 @@ The `nargs` parameter can be set as:
458
463
459
464
<br />
460
465
461
-
#### 6. `greedy` - If this option is set, the argument will consume ALL command-line values until it's upper nargs bound is reached.
466
+
#### Greedy Parsing - If this option is set, the argument will consume ALL command-line values until it's upper nargs bound is reached.
462
467
463
468
> [!NOTE]
464
469
>
@@ -499,7 +504,7 @@ Notice that even though the `-v` and `--type` command-line arguments have flag p
499
504
500
505
<br />
501
506
502
-
#### 7. `choices` - A list of valid argument values.
#### 8. value actions - Functions that are called after parsing an argument's value.
524
+
#### Value Actions - Functions that are called after parsing an argument's value.
520
525
Actions are represented as functions, which take the argument's value as an argument. The available action types are:
521
526
522
527
-`observe` actions | `void(const value_type&)` - applied to the parsed value. No value is returned - this action type is used to perform some logic on the parsed value without modifying it.
@@ -561,7 +566,7 @@ Actions are represented as functions, which take the argument's value as an argu
561
566
562
567
<br />
563
568
564
-
#### 9. `default_values` - A list of values which will be used if no values for an argument have been parsed
569
+
#### Default Values - A list of values which will be used if no values for an argument have been parsed
565
570
566
571
> [!WARNING]
567
572
>
@@ -624,7 +629,7 @@ Command Result
624
629
625
630
Apart from the common parameters listed above, for optional arguments you can also specify the following parameters:
626
631
627
-
#### 1. on-flag actions - Functions that are called immediately after parsing an argument's flag.
632
+
#### On-flag Actions - Functions that are called immediately after parsing an argument's flag.
628
633
629
634
```cpp
630
635
void print_debug_info() noexcept {
@@ -644,7 +649,7 @@ Here the `print_debug_info` function will be called right after parsing the `--d
644
649
645
650
<br />
646
651
647
-
#### 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.
652
+
#### 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.
648
653
649
654
```cpp
650
655
// example
@@ -1607,8 +1612,8 @@ The following table lists the projects provided in the `cpp-argon-demo` submodul
1607
1612
| [Numbers Converter](https://github.com/SpectraL519/cpp-argon-demo/tree/master/numbers_converter/) | Converts numbers between different bases.<br/>**Demonstrates:** The usage of argument parameters such as *nargs*, *choices*, and *default values*. |
1608
1613
| [Verbosity](https://github.com/SpectraL519/cpp-argon-demo/tree/master/verbosity/) | Prints messages with varying levels of verbosity.<br/>**Demonstrates:** The usage of `none_type` arguments and compound argument flags. |
1609
1614
| [Logging Mode](https://github.com/SpectraL519/cpp-argon-demo/tree/master/logging_mode/) | Logs a message depending on the selected logging mode (`quiet`, `normal`, `verbose`).<br/>**Demonstrates:** The usage of custom argument value types (like enums). |
1610
-
| [Message Logger](https://github.com/SpectraL519/cpp-argon-demo/arg_parsertree/master/message_logger/) | Outputs a message to a file, console, or not at all.<br/>**Demonstrates:** The usage of argument groups. |
1611
-
| [AP-GIT](https://github.com/SpectraL519/cpp-argon-demo/tree/master/ap_git/) | A minimal Git CLI clone with subcommands (`init`, `add`, `commit`, `status`, `push`).<br/>**Demonstrates:** The usage of subparsers for multi-command CLIs and complex argument configurations. |
1615
+
| [Message Logger](https://github.com/SpectraL519/cpp-argon-demo/tree/master/message_logger/) | Outputs a message to a file, console, or not at all.<br/>**Demonstrates:** The usage of argument groups. |
1616
+
| [ARGON-GIT](https://github.com/SpectraL519/cpp-argon-demo/tree/master/argon_git/) | A minimal Git CLI clone with subcommands (`init`, `add`, `commit`, `status`, `push`).<br/>**Demonstrates:** The usage of subparsers for multi-command CLIs and complex argument configurations. |
0 commit comments