Skip to content

Commit 451be76

Browse files
authored
Merge pull request #218 from loligans/master
Updated README examples
2 parents bce330d + dd07605 commit 451be76

File tree

1 file changed

+46
-43
lines changed

1 file changed

+46
-43
lines changed

README.md

+46-43
Original file line numberDiff line numberDiff line change
@@ -54,31 +54,28 @@ See more details in the [wiki for direct integrations](https://github.com/gsscod
5454
C# Examples:
5555

5656
```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.")]
6160
public IEnumerable<string> InputFiles { get; set; }
6261

6362
// 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.")]
6764
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.")]
7670
public long? Offset { get; set; }
7771
}
7872

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+
}
8279
```
8380

8481
F# Examples:
@@ -102,25 +99,25 @@ VB.Net:
10299

103100
```VB.NET
104101
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?
121114
End Class
122115

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
124121
```
125122

126123
### For verbs:
@@ -160,20 +157,26 @@ VB.Net example:
160157
```VB.NET
161158
<CommandLine.Verb("add", HelpText:="Add file contents to the index.")>
162159
Public Class AddOptions
163-
'Normal options here
160+
'Normal options here
164161
End Class
165162
<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
168165
End Class
169166
<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
172169
End Class
173170

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
177180
```
178181

179182
F# Example:

0 commit comments

Comments
 (0)