mirror of
				https://github.com/nsnail/spectre.console.git
				synced 2025-11-04 10:35:27 +08:00 
			
		
		
		
	(#916) fixed missing call to Validate when using CommandConstructorBinder
This commit is contained in:
		
				
					committed by
					
						
						Patrik Svensson
					
				
			
			
				
	
			
			
			
						parent
						
							78d841e3dc
						
					
				
				
					commit
					0d19ccd8a6
				
			@@ -0,0 +1,11 @@
 | 
			
		||||
namespace Spectre.Console.Tests.Data;
 | 
			
		||||
 | 
			
		||||
[Description("The turtle command.")]
 | 
			
		||||
public class TurtleCommand : AnimalCommand<TurtleSettings>
 | 
			
		||||
{
 | 
			
		||||
    public override int Execute(CommandContext context, TurtleSettings settings)
 | 
			
		||||
    {
 | 
			
		||||
        DumpSettings(context, settings);
 | 
			
		||||
        return 0;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,7 @@
 | 
			
		||||
namespace Spectre.Console.Tests.Data;
 | 
			
		||||
 | 
			
		||||
public class ReptileSettings : AnimalSettings
 | 
			
		||||
{
 | 
			
		||||
    [CommandOption("-n|-p|--name|--pet-name <VALUE>")]
 | 
			
		||||
    public string Name { get; set; }
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,16 @@
 | 
			
		||||
namespace Spectre.Console.Tests.Data;
 | 
			
		||||
 | 
			
		||||
public sealed class TurtleSettings : ReptileSettings
 | 
			
		||||
{
 | 
			
		||||
    public TurtleSettings(string name)
 | 
			
		||||
    {
 | 
			
		||||
        Name = name;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public override ValidationResult Validate()
 | 
			
		||||
    {
 | 
			
		||||
        return Name != "Lonely George"
 | 
			
		||||
            ? ValidationResult.Error("Only 'Lonely George' is valid name for a turtle!")
 | 
			
		||||
            : ValidationResult.Success();
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user