Last active
November 7, 2019 14:16
-
-
Save gsscoder/4738387 to your computer and use it in GitHub Desktop.
Simple Command Line Parser Library Console Application
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
' needs CommandLine.dll prior to 1.9.4.91 | |
' for later versions: templates are up to date | |
Imports CommandLine | |
Imports CommandLine.Text | |
Imports System.Reflection | |
<Assembly: [AssemblyInformationalVersion]("1.0.0.0")> | |
Friend Class ThisAssembly | |
Friend Shared Title As String = "VBNetTemplate" | |
Friend Shared Author As String = "Your Name Here" | |
Friend Shared Copyright As String = "Copyright (C) 2012 " + Author | |
Friend Shared Version As String = "1.0.0.0" | |
Friend Shared InformationalVersion As String = "1.0.0.0" | |
End Class | |
Friend NotInheritable Class Program | |
Private Class Options | |
Inherits CommandLineOptionsBase | |
<[Option]("t", "text", Required:=True, HelpText:="text value here")> | |
Public Property TextValue As String | |
<[Option]("n", "numeric", HelpText:="numeric value here")> | |
Public Property NumericValue As Double = 0 | |
<[Option]("b", "bool", HelpText:="on|off switch here")> | |
Public Property BooleanValue As Boolean | |
<HelpOption()> | |
Public Function GetUsage() As String | |
Return HelpText.AutoBuild(Me, Sub(current As HelpText) HelpText.DefaultParsingErrorsHandler(Me, current)) | |
End Function | |
End Class | |
Shared Sub Main(args As String()) | |
Dim options = New Options() | |
If CommandLineParser.Default.ParseArguments(args, options) Then | |
Console.WriteLine("t|ext: " + options.TextValue) | |
Console.WriteLine("n|umeric: " & options.NumericValue) | |
Console.WriteLine("b|ool: " & options.BooleanValue.ToString.ToLower) | |
End If | |
End Sub | |
End Class |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment