-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
74e46d5
commit d0a5272
Showing
1 changed file
with
47 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# CLI-Argument-Parser | ||
Library to parse command line arguments - attributes based approach. C# and .netCore | ||
|
||
## How to use it? | ||
|
||
Create a class to hold desired configuration settings, mark with attributes: | ||
|
||
```csharp | ||
public class ProgramConfig | ||
{ | ||
[Option] | ||
[OptionAlias("--help")] | ||
[OptionAlias("-h")] | ||
public bool ShowHelp { get; set; } | ||
|
||
[Option] | ||
[OptionAlias("--version")] | ||
[OptionAlias("-v")] | ||
public bool ShowVersionDetails { get; set; } | ||
|
||
[Option] | ||
[OptionAlias("--age-of-client")] | ||
[OptionAlias("-a")] | ||
public int Age { get; set; } | ||
} | ||
``` | ||
|
||
|
||
Parse it: | ||
```csharp | ||
class Program | ||
{ | ||
static void Main(string[] args) | ||
{ | ||
var parser = new AttributeParser(); | ||
var configuration = parser.Parse<ProgramConfig>(args); | ||
} | ||
} | ||
``` | ||
|
||
Use it in application | ||
```csharp | ||
if (configuration.ShowHelp) | ||
{ | ||
Console.WriteLine("HEEELP"); | ||
} | ||
``` |