Skip to content

IApplicationCommand

Lunar Doggo edited this page Apr 17, 2022 · 1 revision

What is it?

An IApplicationCommand is a single command a CommandApplication will be able to execute.

Implementation

public interface IApplicationCommand

Methods

Sitnature Description
public void Execute() Executes the command

Example

public class AddCommand : IApplicationCommand
{
    private readonly int firstValue, secondValue;

    //Decorate the constructor with the StartOptionGroup-attribute and the parameters with the StartOption-attribute
    //for dependency injection see: IDependencyResolver; after you defined your class, register it as seen in the CommandApplication wiki page
    [StartOptionGroup("add", "a", Description = "Adds two integers together")]
    public AddCommand([StartOption("value-1", "1", Description = "First value", Mandatory = true, ValueType = StartOptionValueType.Single, ParserType = typeof(Int32OptionValueParser))] int firstValue,
                        [StartOption("value-2", "2", Description = "Second value", Mandatory = true, ValueType = StartOptionValueType.Single, ParserType = typeof(Int32OptionValueParser))] int secondValue)
    {
        this.secondValue = secondValue;
        this.firstValue = firstValue;
    }

    public void Execute()
    {
        Console.WriteLine("{0} + {1} = {2}", this.firstValue, this.secondValue, this.firstValue + this.secondValue);
    }
}