Module MainPrompt
Public Const PromptSymbol As String = "TLA > "
Public Const ApplicationTitle As String = GetType(Project.BaseClass).Assembly.FullName
REM Or you can use a custom string
REM Public Const ApplicationTitle As String = "Short name of the application"
Sub Main()
Dim Statement As String
Dim BrokenDownStatement As String()
Dim Command As String
Dim Args As String()
Dim Result As String
Console.ForegroundColor = ConsoleColor.Cyan
Console.Title = ApplicationTitle & " command line console"
Console.WriteLine("Welcome to " & ApplicationTitle & "console frontend")
Console.WriteLine("This package is version " & GetType(Project.BaseClass).Assembly.GetName().Version.ToString)
Console.WriteLine()
Console.Write(PromptSymbol)
Do While True
Statement = Console.ReadLine()
BrokenDownStatement = Statement.Split(" ")
ReDim Args(BrokenDownStatement.Length - 1)
Command = BrokenDownStatement(0)
For i = 1 To BrokenDownStatement.Length - 1
Args(i - 1) = BrokenDownStatement(i)
Next
Select Case Command.ToLower
Case "example"
Result = DoSomething(Example)
Case "exit", "quit"
Exit Do
Case "ver"
Result = "This package is version " & GetType(Project.BaseClass).Assembly.GetName().Version.ToString
Case Else
Result = "Command not acknowldged: -" & Command & "-"
End Select
Console.WriteLine(" " & Result)
Console.Write(PromptSymbol)
Loop
Console.WriteLine("I am exiting, time is " & DateTime.Now.ToString("u"))
Console.WriteLine("Goodbye")
Environment.Exit(0)
End Sub
End Module
This prototype generate a basic command line interpreter.
It automatically get the application name and version to communicate to the user. For each input line, it recognize the command and an arbitrary list of arguments, all separated by space.
As a basic example, this code understand ver, quit and exit commands.
The parameter Project.BaseClass is a class of your project where the Assembly details are set.