This is a nice little command line parser based on
Ray Hayes codeproject article
Automatic Command Line Parsing in C#. I have adapted it to VB.NET and upgraded it to .NET 3.5.
An updated command line parser that has a built in commanding architecture. The usage varies depending on what you are trying to achieve, but you can have commands, nested commands and delegate commands.
You just add this assembly to your project and adda bunch of command objects:
Module DemoModule
Sub Main(ByVal args() As String)
' Create root command collection
Dim root As New CommandCollection("root", Nothing)
' Add "demo1" fixed command
root.AddCommand(New Demo1Command(root))
' Create sub command colleciton
Dim innerlist As New CommandCollection("subcmd", root)
' Add "demo2" delegate comamnd
innerlist.AddCommand(New DelegateCommand(Of Demo3CommandLine)(root, "Demo2", AddressOf OnDemo2Run, AddressOf OnDemo2Validate, "demo 2", "no additional information", "demo 2 command", "This command shows how to delegate the run method using the delegate command"))
' Add "demo3" fixed command
innerlist.AddCommand(New Demo3Command(root))
' Add sub command collcection to root
root.AddCommand(innerlist)
' Start run
root.Run(args)
If Debugger.IsAttached Then
Console.ReadKey()
End If
End Sub
Private Function OnDemo2Run(command As DelegateCommand(Of Demo3CommandLine)) As Integer
Console.WriteLine("Running demo 2")
Return 0
End Function
Private Function OnDemo2Validate(command As DelegateCommand(Of Demo3CommandLine)) As Boolean
Dim isValid As Boolean = True
If String.IsNullOrEmpty(command.CommandLine.Value1) Then
isValid = False
End If
Return isValid
End Function
End Module