Creating Commands

Creating new commands is simple. Theta commands are simply classes that are decorated with attributes from the Credera.Theta.API namespace which give the command its behavior.

Creating the Command Class

  1. Start by creating a new public class in a project which references the Credera.Theta assembly.
  2. All command classes must have the following elements - add these now
    1. Decorate the class with the Credera.Theta.API.Command attribute - populate the attributes name parameter to specify a name for the command, or leave it blank to use the class' name
    2. The command class should extend the Credera.Theta.API.InputCommand class which provides common switches and parameters as well as access to the HostInterface
    3. Extending the InputCommand class will force you to implement the abstract Invoke function which is called when your command is successfully invoked from the command line

see also Command Attribute, InputCommand

Adding Parameters

Parameters are simply class properties decorated with the Credera.Theta.API.Parameter attribute. Make sure that the property is of string data type and has a public setter.

see also Parameter Attribute

Adding Switches

Switches are also class properties decorated with the Credera.Theta.API.Switch attribute. The switch property must be of the Credera.Theta.API.SwitchParameter data type and must also have a public setter.

see also Switch Attribute, SwitchParameter

Aliases

The command class as well as parameter and switch properties may also be decorated with one or more Credera.Theta.API.Alias attributes. Each alias attribute defines an alias which can also be used to reference the command, parameter or switch from the command line.

see also Alias Attribute

Synopsis

The command class as well as parameter and switch properties may also be decorated with a Credera.Theta.API.Synopsis attribute. The synopsis attribute defines a brief synopsis for the command class, parameter or switch and is used for self documentation.

see also Synopsis Attribute, Help Command

Example

using Credera.Theta.API;
using System;

namespace Credera.Theta.Commands
{
    [Command("Test")]
    [Alias("tst")]
    [Synopsis("This is a test command")]
    class TestCommand : InputCommand
    {
        [Parameter]
        [Synopsis("This parameter is called ParameterOne")]
        public string ParameterOne { get; set; }

        [Parameter]
        public string ParameterTwo { get; set; }

        [Switch]
        [Synopsis("When this switch is present, it enables some cool functionality")]
        public SwitchParameter OutputToLog { get; set; }

        public override void Invoke(CommandInvocationContext context)
        {
            base.Out.Standard.WriteLine("I have been invoked!");
        }
    }
}


That's it! When your command is successfully invoked from the command line, the properties and switches will be set and the Invoke function of your command will be called. For examples of command classes, take a look at the Out of the Box Commands found in the Credera.Theta.Commands namespace.

see also Command API, Registering Commands, Commands

Last edited Jun 15, 2013 at 7:55 PM by jeffhewitt, version 11

Comments

No comments yet.