Commands - adamconnelly/dbversion GitHub Wiki

The dbversion console application uses commands to work. The command system is made up of two items: the command manager; and commands that the manager can run. The command manager imports commands that export the IConsoleCommand interface.

Using the Application

To run a dbversion command, you should type:

dbversion [command name] [options]

The options available depend on the command that you want to run. To get a list of the commands that are available, use the help command:

dbversion help

To get more information on a particular command, pass the command name as the argument to the help command:

dbversion help [command name]

For example:

dbversion help create

List of Commands

The following is a list of the current known commands for dbversion:

Command Manager

The command manager parses the command line arguments and figures out which command to execute. Once it has identified the command to execute, it calls the command's execute method and passes it the command line arguments.

The command manager imports a collection of all of the IConsoleCommand objects that have been exported, so to add a new command to the application you just need to implement the IConsoleCommand interface and export your new object.

IConsoleCommand Interface

The IConsoleCommand interface defines a command that can be run as part of dbversion:

public interface IConsoleCommand
{
    string Name { get; }
    string Description { get; }
    string Usage { get; }
    IEnumerable<CommandParameter> Parameters { get; }
    void Execute(string[] arguments);
}

For more information about the members of IConsoleCommand, look at the source code. It is also worth taking a look at some of the implementations of the interface, along with their associated unit tests.

Please note that if your command requires a connection to the database, you should inherit from ConnectionCommandBase. This base class ensures that all commands that connect to the database support the same connection arguments, and use the saved connection and property services properly to make sure that the connection information is merged in the correct order.