@@ -46,6 +46,43 @@ You can utilize the parser library in several ways:
46
46
1 . Create a class to define valid options, and to receive the parsed options.
47
47
2 . Call ParseArguments with the args string array.
48
48
49
+ C# Quick Start:
50
+
51
+ ``` csharp
52
+ using System ;
53
+ using CommandLine ;
54
+
55
+ namespace QuickStart
56
+ {
57
+ class Program
58
+ {
59
+ public class Options
60
+ {
61
+ [Option ('v' , " verbose" , Required = false , HelpText = " Set output to verbose messages." )]
62
+ public bool Verbose { get ; set ; }
63
+ }
64
+
65
+ static void Main (string [] args )
66
+ {
67
+ Parser .Default .ParseArguments <Options >(args )
68
+ .WithParsed <Options >(o =>
69
+ {
70
+ if (o .Verbose )
71
+ {
72
+ Console .WriteLine ($" Verbose output enabled. Current Arguments: -v {o .Verbose }" );
73
+ Console .WriteLine (" Quick Start Example! App is in Verbose mode!" );
74
+ }
75
+ else
76
+ {
77
+ Console .WriteLine ($" Current Arguments: -v {o .Verbose }" );
78
+ Console .WriteLine (" Quick Start Example!" );
79
+ }
80
+ });
81
+ }
82
+ }
83
+ }
84
+ ```
85
+
49
86
C# Examples:
50
87
51
88
``` csharp
@@ -55,10 +92,14 @@ class Options
55
92
public IEnumerable <string > InputFiles { get ; set ; }
56
93
57
94
// Omitting long name, defaults to name of property, ie "--verbose"
58
- [Option (Default = false , HelpText = " Prints all messages to standard output." )]
95
+ [Option (
96
+ Default = false ,
97
+ HelpText = " Prints all messages to standard output." )]
59
98
public bool Verbose { get ; set ; }
60
-
61
- [Option (" stdin" , Default = false , HelpText = " Read from stdin" )]
99
+
100
+ [Option (" stdin" ,
101
+ Default = false
102
+ HelpText = " Read from stdin" )]
62
103
public bool stdin { get ; set ; }
63
104
64
105
[Value (0 , MetaName = " offset" , HelpText = " File offset." )]
@@ -79,7 +120,7 @@ F# Examples:
79
120
type options = {
80
121
[<Option('r', "read", Required = true, HelpText = "Input files.")>] files : seq<string>;
81
122
[<Option(HelpText = "Prints all messages to standard output.")>] verbose : bool;
82
- [<Option(DefaultValue = "русский", HelpText = "Content language.")>] language : string;
123
+ [<Option(Default = "русский", HelpText = "Content language.")>] language : string;
83
124
[<Value(0, MetaName="offset", HelpText = "File offset.")>] offset : int64 option;
84
125
}
85
126
@@ -94,18 +135,22 @@ VB.Net:
94
135
95
136
``` VB.NET
96
137
Class Options
97
- <CommandLine.Option( "r" , "read" , Required:= True , HelpText:= "Input files to be processed." )>
98
- Public Property InputFiles As IEnumerable( Of String )
99
-
100
- ' Omitting long name, defaults to name of property, ie "--verbose"
101
- <CommandLine.Option(HelpText:= "Prints all messages to standard output." )>
102
- Public Property Verbose As Boolean
103
-
104
- <CommandLine.Option([Default]:= "中文" , HelpText:= "Content language." )>
105
- Public Property Language As String
106
-
107
- <CommandLine.Value( 0 , MetaName:= "offset" , HelpText:= "File offset." )>
108
- Public Property Offset As Long ?
138
+ <CommandLine.Option( 'r', "read", Required := true,
139
+ HelpText:= "Input files to be processed." )>
140
+ Public Property InputFiles As IEnumerable( Of String )
141
+
142
+ ' Omitting long name, defaults to name of property, ie "--verbose"
143
+ <CommandLine.Option(
144
+ HelpText:= "Prints all messages to standard output." )>
145
+ Public Property Verbose As Boolean
146
+
147
+ <CommandLine.Option( Default := "中文" ,
148
+ HelpText:= "Content language." )>
149
+ Public Property Language As String
150
+
151
+ <CommandLine.Value( 0 , MetaName:= "offset" ,
152
+ HelpText:= "File offset." )>
153
+ Public Property Offset As Long ?
109
154
End Class
110
155
111
156
Sub Main( ByVal args As String ())
0 commit comments