Skip to content

Commit

Permalink
Update documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
yakovypg committed Aug 10, 2024
1 parent e9ef5ab commit 92917b2
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions Documentation/OptionalArguments.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Let's consider **optional arguments**. Optional arguments start with `-`, `--` o
* [Value Options](#value-options)
* [Multiple Value Options](#multiple-value-options)
* [Enum Value Options](#enum-value-options)
* [Final Options](#final-options)
* [Custom Options](#custom-options)
* [Option Groups](#option-groups)
* [Mutual Exclusion](#mutual-exclusion)
Expand Down Expand Up @@ -189,6 +190,37 @@ parser.Parse(new string[] { "--split-option", "TrimEntries" });
// splitOption: StringSplitOptions.TrimEntries
```

## Final Options
**Final options** are options that are handled before all others. After the final option is handled, the remaining options (including final ones) aren't handled. Examples of final options are help option and version option.

Note that options of any type can be final. To make an option final, you need to set the corresponding value to the `isFinal` parameter of the option constructor.

Here is an example of creating final option and using it in the parser:

```cs
int? angle = null;
int? width = null;
int? final = null;

var angleOption = new ValueOption<int>("angle", "a",
afterValueParsingAction: t => angle = t);

var widthOption = new ValueOption<int>("width", "w",
afterValueParsingAction: t => width = t);

var finalOption = new ValueOption<int>("final", string.Empty,
isFinal: true,
afterValueParsingAction: t => final = t);

var parser = new ArgumentParser();
parser.AddOptions(angleOption, widthOption, finalOption);

parser.Parse(new string[] { "-a", "40", "--final", "100", "-w", "1920" });
// angle: null
// width: null
// final: 100
```

## Custom Options
You can create your own options. To do this you need to inherit your class from the `ICommonOption` interface and implement it. You can also use an existing option class as a base class. See examples of this kind of inheritance, for example, by looking at the implementation of the `FlagOption` and `EnumValueOption` classes. Next, you can use this class in the same way as the standard ones.

Expand Down

0 comments on commit 92917b2

Please sign in to comment.