File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ # libArgument
2+ libArgument is a .NET library for handling command-line arguments like a boss.
3+ It allows you to validate arguments on-the-fly and saves you hours of work.
4+
5+ Features:
6+
7+ * 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+
12+ And here's some code!
13+
14+ ``` cs
15+ using Codeaddicts .libArguments ;
16+ using Codeaddicts .libArguments .Attributes ;
17+
18+ // A simple class with some command-line options
19+ public class MyOptions
20+ {
21+ // -i path/to/file
22+ // --input path/to/file
23+ [Argument (" i" , " input" )]
24+ public string Input ;
25+
26+ // -o path/to/file
27+ // --output path/to/file
28+ [Argument (" o" , " output" )]
29+ public string Output ;
30+
31+ // --log
32+ [Switch (" " , " log" )]
33+ public bool EnableLog ;
34+
35+ // --num 123
36+ [Argument (" " , " num" )]
37+ [CastAs (CastingType .UInt64 )]
38+ public UInt64 ANumber ;
39+ }
40+
41+ public class Program
42+ {
43+ public static void Main (string [] args ) {
44+
45+ // This is where the magic happens
46+ var options = ArgumentParser .Parse <MyOptions > (args );
47+
48+ // Now you can access the fields!
49+ Console .WriteLine (" Input file: " + options .Input );
50+ Console .WriteLine (" Output file: " + options .Output );
51+ Console .WriteLine (" Your number: " + options .ANumber );
52+ }
53+ }
54+ ```
You can’t perform that action at this time.
0 commit comments