@@ -54,31 +54,28 @@ See more details in the [wiki for direct integrations](https://github.com/gsscod
54
54
C# Examples:
55
55
56
56
``` csharp
57
- internal class Options {
58
- [Option ('r' ," read" ,
59
- Required = true ,
60
- HelpText = " Input files to be processed." )]
57
+ class Options
58
+ {
59
+ [Option ('r' , " read" , Required = true , HelpText = " Input files to be processed." )]
61
60
public IEnumerable <string > InputFiles { get ; set ; }
62
61
63
62
// Omitting long name, defaults to name of property, ie "--verbose"
64
- [Option (
65
- DefaultValue = false ,
66
- HelpText = " Prints all messages to standard output." )]
63
+ [Option (Default = false , HelpText = " Prints all messages to standard output." )]
67
64
public bool Verbose { get ; set ; }
68
-
69
- [Option (" stdin" ,
70
- DefaultValue = false
71
- HelpText = " Read from stdin" )]
72
- public bool stdin { get ; set ; }
73
-
74
- [Value (0 , MetaName = " offset" ,
75
- HelpText = " File offset." )]
65
+
66
+ [Option (" stdin" , Default = false , HelpText = " Read from stdin" )]
67
+ public bool stdin { get ; set ; }
68
+
69
+ [Value (0 , MetaName = " offset" , HelpText = " File offset." )]
76
70
public long ? Offset { get ; set ; }
77
71
}
78
72
79
- static int Main (string [] args ) {
80
- var options = new Options ();
81
- var isValid = CommandLine .Parser .Default .ParseArgumentsStrict (args , options );
73
+ static void Main (string [] args )
74
+ {
75
+ CommandLine .Parser .Default .ParseArguments <Options >(args )
76
+ .WithParsed <Options >(opts => RunOptionsAndReturnExitCode (opts ))
77
+ .WithNotParsed <Options >((errs ) => HandleParseError (errs ));
78
+ }
82
79
```
83
80
84
81
F# Examples:
@@ -102,25 +99,25 @@ VB.Net:
102
99
103
100
``` VB.NET
104
101
Class Options
105
- <CommandLine.Option('r', "read", Required := true,
106
- HelpText:="Input files to be processed.")>
107
- Public Property InputFiles As IEnumerable(Of String)
108
-
109
- ' Omitting long name, defaults to name of property, ie "--verbose"
110
- <CommandLine.Option(
111
- HelpText:="Prints all messages to standard output.")>
112
- Public Property Verbose As Boolean
113
-
114
- <CommandLine.Option(DefaultValue:="中文",
115
- HelpText:="Content language.")>
116
- Public Property Language As String
117
-
118
- <CommandLine.Value(0, MetaName:="offset",
119
- HelpText:="File offset.")>
120
- Public Property Offset As Long?
102
+ <CommandLine.Option( "r" , "read" , Required:= True , HelpText:= "Input files to be processed." )>
103
+ Public Property InputFiles As IEnumerable( Of String )
104
+
105
+ ' Omitting long name, defaults to name of property, ie "--verbose"
106
+ <CommandLine.Option(HelpText:= "Prints all messages to standard output." )>
107
+ Public Property Verbose As Boolean
108
+
109
+ <CommandLine.Option([Default]:= "中文" , HelpText:= "Content language." )>
110
+ Public Property Language As String
111
+
112
+ <CommandLine.Value( 0 , MetaName:= "offset" , HelpText:= "File offset." )>
113
+ Public Property Offset As Long ?
121
114
End Class
122
115
123
- 'TODO
116
+ Sub Main( ByVal args As String ())
117
+ CommandLine.Parser.Default.ParseArguments( Of Options)(args) _
118
+ .WithParsed( Function (opts As Options) RunOptionsAndReturnExitCode(opts)) _
119
+ .WithNotParsed( Function (errs As IEnumerable( Of [Error])) 1 )
120
+ End Sub
124
121
```
125
122
126
123
### For verbs:
@@ -160,20 +157,26 @@ VB.Net example:
160
157
``` VB.NET
161
158
<CommandLine.Verb( "add" , HelpText:= "Add file contents to the index." )>
162
159
Public Class AddOptions
163
- 'Normal options here
160
+ 'Normal options here
164
161
End Class
165
162
<CommandLine.Verb( "commit" , HelpText:= "Record changes to the repository." )>
166
- Public Class AddOptions
167
- 'Normal options here
163
+ Public Class CommitOptions
164
+ 'Normal options here
168
165
End Class
169
166
<CommandLine.Verb( "clone" , HelpText:= "Clone a repository into a new directory." )>
170
- Public Class AddOptions
171
- 'Normal options here
167
+ Public Class CloneOptions
168
+ 'Normal options here
172
169
End Class
173
170
174
- Public Shared Sub Main ()
175
- 'TODO
176
- End Sub
171
+ Function Main( ByVal args As String ()) As Integer
172
+ Return CommandLine.Parser.Default.ParseArguments( Of AddOptions, CommitOptions, CloneOptions)(args) _
173
+ .MapResult(
174
+ ( Function (opts As AddOptions) RunAddAndReturnExitCode(opts)),
175
+ ( Function (opts As CommitOptions) RunCommitAndReturnExitCode(opts)),
176
+ ( Function (opts As CloneOptions) RunCloneAndReturnExitCode(opts)),
177
+ ( Function (errs As IEnumerable( Of [Error])) 1 )
178
+ )
179
+ End Function
177
180
```
178
181
179
182
F# Example:
0 commit comments