From 46bf0bc0b6ab9b9a41cc5c1c1cc41595910a465b Mon Sep 17 00:00:00 2001 From: Ethan Lindemann-Michael Date: Thu, 11 Jan 2018 19:23:30 -0800 Subject: [PATCH 1/3] Added VB.NET Verb example code. --- README.md | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index a8efcb5e..e3b7daeb 100644 --- a/README.md +++ b/README.md @@ -160,20 +160,26 @@ VB.Net example: ```VB.NET Public Class AddOptions - 'Normal options here + 'Normal options here End Class -Public Class AddOptions - 'Normal options here +Public Class CommitOptions + 'Normal options here End Class -Public Class AddOptions - 'Normal options here +Public Class CloneOptions + 'Normal options here End Class -Public Shared Sub Main() - 'TODO -End Sub +Function Main(ByVal args As String()) As Integer + Return CommandLine.Parser.Default.ParseArguments(Of AddOptions, CommitOptions, CloneOptions)(args) _ + .MapResult( + (Function(opts As AddOptions) RunAddAndReturnExitCode(opts)), + (Function(opts As CommitOptions) RunCommitAndReturnExitCode(opts)), + (Function(opts As CloneOptions) RunCloneAndReturnExitCode(opts)), + (Function(errs As IEnumerable(Of [Error])) 1) + ) +End Function ``` F# Example: From 9cb0e3099828210e6e1b3d68f231d3b07e246ffe Mon Sep 17 00:00:00 2001 From: Ethan Lindemann-Michael Date: Thu, 11 Jan 2018 19:52:22 -0800 Subject: [PATCH 2/3] Updated VB.NET quick start example --- README.md | 46 +++++++++++++++++++++++----------------------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/README.md b/README.md index e3b7daeb..4fe557ec 100644 --- a/README.md +++ b/README.md @@ -102,25 +102,25 @@ VB.Net: ```VB.NET Class Options - - Public Property InputFiles As IEnumerable(Of String) - - ' Omitting long name, defaults to name of property, ie "--verbose" - - Public Property Verbose As Boolean - - - Public Property Language As String - - - Public Property Offset As Long? + + Public Property InputFiles As IEnumerable(Of String) + + ' Omitting long name, defaults to name of property, ie "--verbose" + + Public Property Verbose As Boolean + + + Public Property Language As String + + + Public Property Offset As Long? End Class -'TODO +Sub Main(ByVal args As String()) + CommandLine.Parser.Default.ParseArguments(Of Options)(args) _ + .WithParsed(Function(opts As Options) RunOptionsAndReturnExitCode(opts)) _ + .WithNotParsed(Function(errs As IEnumerable(Of [Error])) 1) +End Sub ``` ### For verbs: @@ -173,12 +173,12 @@ End Class Function Main(ByVal args As String()) As Integer Return CommandLine.Parser.Default.ParseArguments(Of AddOptions, CommitOptions, CloneOptions)(args) _ - .MapResult( - (Function(opts As AddOptions) RunAddAndReturnExitCode(opts)), - (Function(opts As CommitOptions) RunCommitAndReturnExitCode(opts)), - (Function(opts As CloneOptions) RunCloneAndReturnExitCode(opts)), - (Function(errs As IEnumerable(Of [Error])) 1) - ) + .MapResult( + (Function(opts As AddOptions) RunAddAndReturnExitCode(opts)), + (Function(opts As CommitOptions) RunCommitAndReturnExitCode(opts)), + (Function(opts As CloneOptions) RunCloneAndReturnExitCode(opts)), + (Function(errs As IEnumerable(Of [Error])) 1) + ) End Function ``` From dd0760557692f3fd6b7920192fd4b0b0df85c673 Mon Sep 17 00:00:00 2001 From: Ethan Lindemann-Michael Date: Thu, 11 Jan 2018 21:18:01 -0800 Subject: [PATCH 3/3] Updated C# quick start example to work with the newer API. --- README.md | 33 +++++++++++++++------------------ 1 file changed, 15 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index 4fe557ec..62884488 100644 --- a/README.md +++ b/README.md @@ -54,31 +54,28 @@ See more details in the [wiki for direct integrations](https://github.com/gsscod C# Examples: ```csharp -internal class Options { - [Option('r',"read", - Required = true, - HelpText = "Input files to be processed.")] +class Options +{ + [Option('r', "read", Required = true, HelpText = "Input files to be processed.")] public IEnumerable InputFiles { get; set; } // Omitting long name, defaults to name of property, ie "--verbose" - [Option( - DefaultValue = false, - HelpText = "Prints all messages to standard output.")] + [Option(Default = false, HelpText = "Prints all messages to standard output.")] public bool Verbose { get; set; } - - [Option("stdin", - DefaultValue = false - HelpText = "Read from stdin")] - public bool stdin { get; set; } - - [Value(0, MetaName = "offset", - HelpText = "File offset.")] + + [Option("stdin", Default = false, HelpText = "Read from stdin")] + public bool stdin { get; set; } + + [Value(0, MetaName = "offset", HelpText = "File offset.")] public long? Offset { get; set; } } -static int Main(string[] args) { - var options = new Options(); - var isValid = CommandLine.Parser.Default.ParseArgumentsStrict(args, options); +static void Main(string[] args) +{ + CommandLine.Parser.Default.ParseArguments(args) + .WithParsed(opts => RunOptionsAndReturnExitCode(opts)) + .WithNotParsed((errs) => HandleParseError(errs)); +} ``` F# Examples: