|
2 | 2 | libArgument is a .NET library for handling command-line arguments like a boss. |
3 | 3 | It allows you to validate arguments on-the-fly and saves you hours of work. |
4 | 4 |
|
| 5 | +If you want to test the latest features, please download the source and compile it yourself. |
| 6 | +The release may not be up-to-date. |
| 7 | + |
5 | 8 | Features: |
6 | 9 |
|
7 | 10 | * The generic parsing method works with any class |
8 | | -* Create boolean switches with the 'Switch' attribute |
9 | | -* Create arguments with parameters using the 'Argument' attribute |
10 | | -* Cast argument texts to int32, int64, bool, float etc. using the 'CastAs' attribute |
| 11 | +* Boolean switches with the 'Switch' attribute |
| 12 | +* Arguments with parameters using the 'Argument' attribute |
| 13 | +* Automatically casts the argument to the type of the variable |
| 14 | +* Automatically infers the argument name from the variable name if no argument name is given |
| 15 | +* Allows you to use multiple argument or switch names for one variable |
| 16 | + |
| 17 | +## How does it work? |
| 18 | +It's really easy. |
| 19 | +Here's a small example: |
| 20 | + |
| 21 | +```cs |
| 22 | +using Codeaddicts.libArgument; |
| 23 | +using Codeaddicts.libArgument.Attributes; |
| 24 | + |
| 25 | +// A simple class with some command-line options |
| 26 | +public class MyOptions { |
| 27 | + [Argument] public string input; |
| 28 | + [Argument] public string output; |
| 29 | + [Switch] public bool verbose; |
| 30 | +} |
| 31 | + |
| 32 | +public class Program { |
| 33 | + public static void Main (string[] args) { |
| 34 | + // Let the magic happen |
| 35 | + var options = ArgumentParser.Parse<MyOptions> (args); |
| 36 | + |
| 37 | + // That's it! Now you can use the variables |
| 38 | + Console.WriteLine ("Input: {0}", options.input); |
| 39 | + Console.WriteLine ("Output: {0}", options.output); |
| 40 | + Console.WriteLine ("Verbose: {0}", options.verbose ? "yes" : "no"); |
| 41 | + } |
| 42 | +} |
| 43 | +``` |
| 44 | + |
| 45 | +Call the program like that: |
| 46 | +$ MyApp.exe --input "path/to/input" --output "path/to/output" --verbose |
11 | 47 |
|
12 | | -And here's some code! |
| 48 | +## Can I do more advanced stuff? |
| 49 | +Sure! You can do pretty much everything :P |
| 50 | +Here's some more advanced code for you. |
13 | 51 |
|
14 | 52 | ```cs |
15 | 53 | using Codeaddicts.libArgument; |
|
0 commit comments