This project is read-only.

Command Console Framework


Project Description

Instantly create a keyword-driven console application by referencing and importing the Command Console Framework, and then writing simple sub routines marked with the CommandMethod attribute.

.Net Framework Version 4.0

Written in VB.Net


Instantly create feature-rich console applications by referencing and importing the CommandConsoleFramework in a new Windows Console Application project. The framework provides static CommandInterpreter, and ConsoleOutput classes to handle the processing of user command input and the structured writing of console output. The interpreter provides the ability to track executed commands and log activity to an internal event list. The ConsoleOutput class provides a formatting markup capability which can process console changes such as color and cursor position from tags embedded in the output text. The formatting method will also break the output into lines of whole words and manage the "(more...)" mechanic to keep long text from overflowing.

There are multiple ways for your application to process user input as custom commands, from decorating methods with attributes, to custom classes, to using event handlers (or all of them!). The interpreter also contains a number of built-in commands which will be handled automatically; these include commands like Exit, Help, Clear, and Showlog. See the Documentation for information on how to customize the default commands.

The quickest way to create a new console application based on the framework is by placing attributes on methods with the appropriate signature local to the console application's main module. Here is an example console application with an "Add" command implemented:

Imports CommandConsoleFramework

Module Module1
    Sub Main()
    End Sub

    <CommandMethod("Adds a series of numbers.", "Outputs the sum of the supplied list of numbers.")>
    <CommandMethodArgument("Numbers", "The list of decimal numbers to add, seperated by spaces.")>
    Sub Add(line As CommandLine)
        If line.ArgumentString.Length > 0 Then
            Dim result, testNumber As Decimal
            For wordIndex As Integer = 1 To line.Words.Length - 1
                Dim word As String = line.Words(wordIndex).Word
                If Decimal.TryParse(word, testNumber) Then
                    result += testNumber
                    ConsoleOutput.WriteIndentedColored(5, ConsoleColor.Red, True, "Invalid decimal number: {0}", word)
                End If
            line.SetResultMessage("No numbers to add.", True)
        End If
    End Sub
End Module

So any method on the local module with the signature Sub MethodName(ByVal line As CommandLine) can be decorated with the CommandMethod attribute and it will automatically be picked up as a the method target of a user command by the interpreter. There are other ways to register methods with the interpreter, but any static class with decorated methods will automatically be registered.

The CommandMethodArgument attribute can be applied multiple times to define the help text for each argument expected by the command. The CommandMethod attribute has multiple constructors to provide help text for the command or to hide the from the help system.

With just this code, not only can we handle a command to "add" multiple numbers but we also get a lot of other rich functionality with the application. Here are a few images demonstrating this program:







See the Doumentation for more information.

Last edited May 18, 2012 at 11:27 PM by ReedKimble, version 9