命令行提示原型
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
该原型生成一个基本的命令行解释器。
它会自动获取应用程序名称和版本以与用户进行通信。对于每个输入行,它识别命令和任意参数列表,所有参数都用空格分隔。
作为一个基本示例,此代码了解 ver , quit 和 exit 命令。
参数 Project.BaseClass 是项目的一个类,其中设置了程序集详细信息。