[Command("MATH.ADD", "Add two integer values.")]
public class AddCommand : CommandBase2<AdditionContext>
{
public AddCommand(IServiceProvider serviceProvider) : base(serviceProvider) {}
protected override void Execute()
{
int result = this.Context.Value1 + this.Context.Value2;
Console.WriteLine($"{this.Context.Value1} + {this.Context.Value2} = {result}");
}
}
[Command("MATH.SUB", "Subtract two integer values.")]
public class SubCommand : CommandBase2<AdditionContext>
{
public SubCommand(IServiceProvider serviceProvider) : base(serviceProvider) {}
protected override void Execute()
{
int result = Context.Value1 - Context.Value2;
Console.WriteLine($"{Context.Value1} - {Context.Value2} = {result}");
}
}
public class AdditionContext
{
[OptionDescriptor(
"Value1", new []{"a1", "a"},
required:true, defaultValue:0, helpText : "The first addend or the minuend." )]
public int Value1 { get; set; }
[OptionDescriptor(
"Value2", new []{"a2","b"},
required:true, defaultValue:0, helpText : "The second addend or the subtrahend." )]
public int Value2 { get; set; }
}