11using Spectre . Console . Cli ;
22using System . ComponentModel ;
3+ using Spectre . Console ;
34
45namespace App01 ;
56
@@ -11,11 +12,13 @@ public static int Main(string[] args)
1112
1213 app . Configure ( config =>
1314 {
14- config . AddCommand < UpperCommand > ( Constants . UpperCommandName )
15+ config
16+ . AddCommand < UpperCommand > ( Constants . UpperCommandName )
1517 . WithAlias ( Constants . UpperCommandAlias )
1618 . WithDescription ( Constants . UpperCommandDescription ) ;
1719
18- config . AddCommand < LowerCommand > ( Constants . LowerCommandName )
20+ config
21+ . AddCommand < LowerCommand > ( Constants . LowerCommandName )
1922 . WithAlias ( Constants . LowerCommandAlias )
2023 . WithDescription ( Constants . LowerCommandDescription ) ;
2124 } ) ;
@@ -25,7 +28,7 @@ public static int Main(string[] args)
2528
2629 private class UpperCommand : Command < InputSetting >
2730 {
28- public override int Execute ( CommandContext context , InputSetting settings , CancellationToken cancellationToken )
31+ protected override int Execute ( CommandContext context , InputSetting settings , CancellationToken cancellationToken )
2932 {
3033 Constants . Color . WriteLine ( $ "Upper = '{ settings . Input . ToUpper ( ) } '") ;
3134 return 0 ;
@@ -34,7 +37,7 @@ public override int Execute(CommandContext context, InputSetting settings, Cance
3437
3538 private sealed class LowerCommand : Command < InputSetting >
3639 {
37- public override int Execute ( CommandContext context , InputSetting settings , CancellationToken cancellationToken )
40+ protected override int Execute ( CommandContext context , InputSetting settings , CancellationToken cancellationToken )
3841 {
3942 Constants . Color . WriteLine ( $ "Lower = '{ settings . Input . ToLower ( ) } '") ;
4043 return 0 ;
@@ -46,5 +49,12 @@ private sealed class InputSetting : CommandSettings
4649 [ Description ( Constants . InputOptionDescription ) ]
4750 [ CommandOption ( "-i|--input <INPUT>" ) ]
4851 public string Input { get ; init ; }
52+
53+ public override ValidationResult Validate ( )
54+ {
55+ return string . IsNullOrWhiteSpace ( Input )
56+ ? ValidationResult . Error ( "Input '-i|--input' is required." )
57+ : ValidationResult . Success ( ) ;
58+ }
4959 }
5060}
0 commit comments