@@ -46,6 +46,43 @@ You can utilize the parser library in several ways:
46461 . Create a class to define valid options, and to receive the parsed options.
47472 . Call ParseArguments with the args string array.
4848
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+
4986C# Examples:
5087
5188``` csharp
@@ -55,10 +92,14 @@ class Options
5592 public IEnumerable <string > InputFiles { get ; set ; }
5693
5794 // 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." )]
5998 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" )]
62103 public bool stdin { get ; set ; }
63104
64105 [Value (0 , MetaName = " offset" , HelpText = " File offset." )]
@@ -79,7 +120,7 @@ F# Examples:
79120type options = {
80121 [<Option('r', "read", Required = true, HelpText = "Input files.")>] files : seq<string>;
81122 [<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;
83124 [<Value(0, MetaName="offset", HelpText = "File offset.")>] offset : int64 option;
84125}
85126
@@ -94,18 +135,22 @@ VB.Net:
94135
95136``` VB.NET
96137Class 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 ?
109154End Class
110155
111156Sub Main( ByVal args As String ())
@@ -204,7 +249,7 @@ let main args =
204249 | :? CommandLine.NotParsed<obj> -> 1
205250```
206251
207- # Contibutors
252+ # Contributors
208253First off, _ Thank you!_ All contributions are welcome.
209254
210255Please consider sticking with the GNU getopt standard for command line parsing.
0 commit comments