Add parameter value provider support

Adds support for parameter value providers which makes it
possible to set custom values for parameters.
This commit is contained in:
Patrik Svensson
2021-05-08 07:42:28 +02:00
committed by Phil Scott
parent d1d94cdebe
commit 1dd1945297
14 changed files with 208 additions and 27 deletions

View File

@ -11,19 +11,19 @@ namespace Spectre.Console.Tests.Data
{
}
public override ValidationResult Validate(ICommandParameterInfo info, object value)
public override ValidationResult Validate(CommandParameterContext context)
{
if (value is int integer)
if (context.Value is int integer)
{
if (integer % 2 == 0)
{
return ValidationResult.Success();
}
return ValidationResult.Error($"Number is not even ({info?.PropertyName}).");
return ValidationResult.Error($"Number is not even ({context.Parameter.PropertyName}).");
}
throw new InvalidOperationException($"Parameter is not a number ({info?.PropertyName}).");
throw new InvalidOperationException($"Parameter is not a number ({context.Parameter.PropertyName}).");
}
}
}