44#nullable disable
55
66using System . CommandLine ;
7+ using System . CommandLine . Invocation ;
78using Microsoft . DotNet . Cli . Commands . Workload . Clean ;
89using Microsoft . DotNet . Cli . Commands . Workload . Config ;
910using Microsoft . DotNet . Cli . Commands . Workload . Elevate ;
@@ -27,17 +28,18 @@ namespace Microsoft.DotNet.Cli.Commands.Workload;
2728internal static class WorkloadCommandParser
2829{
2930 public static readonly string DocsLink = "https://aka.ms/dotnet-workload" ;
30-
3131 public static readonly Option < bool > InfoOption = new ( "--info" )
3232 {
3333 Description = CliCommandStrings . WorkloadInfoDescription ,
34- Arity = ArgumentArity . Zero
34+ Arity = ArgumentArity . Zero ,
35+ Action = new ShowWorkloadsInfoAction ( )
3536 } ;
3637
3738 public static readonly Option < bool > VersionOption = new ( "--version" )
3839 {
3940 Description = CliCommandStrings . WorkloadVersionDescription ,
40- Arity = ArgumentArity . Zero
41+ Arity = ArgumentArity . Zero ,
42+ Action = new ShowWorkloadsVersionOption ( )
4143 } ;
4244
4345 public static Command GetCommand ( )
@@ -78,11 +80,11 @@ void WriteUpdateModeAndAnyError(string indent = "")
7880 reporter . WriteLine ( indent + CliCommandStrings . ShouldInstallAWorkloadSet ) ;
7981 }
8082 }
81-
83+
8284 if ( showVersion )
8385 {
8486 reporter . WriteLine ( $ " Workload version: { GetWorkloadsVersion ( ) } ") ;
85-
87+
8688 WriteUpdateModeAndAnyError ( indent : " " ) ;
8789 reporter . WriteLine ( ) ;
8890 }
@@ -134,22 +136,7 @@ void WriteUpdateModeAndAnyError(string indent = "")
134136 }
135137 }
136138
137- private static int ProcessArgs ( ParseResult parseResult )
138- {
139- if ( parseResult . HasOption ( InfoOption ) && parseResult . RootSubCommandResult ( ) == "workload" )
140- {
141- ShowWorkloadsInfo ( parseResult ) ;
142- Reporter . Output . WriteLine ( string . Empty ) ;
143- return 0 ;
144- }
145- else if ( parseResult . HasOption ( VersionOption ) && parseResult . RootSubCommandResult ( ) == "workload" )
146- {
147- Reporter . Output . WriteLine ( GetWorkloadsVersion ( ) ) ;
148- Reporter . Output . WriteLine ( string . Empty ) ;
149- return 0 ;
150- }
151- return parseResult . HandleMissingCommand ( ) ;
152- }
139+ private static int ProcessArgs ( ParseResult parseResult ) => parseResult . HandleMissingCommand ( ) ;
153140
154141 private static Command ConstructCommand ( )
155142 {
@@ -182,4 +169,34 @@ private static Command ConstructCommand()
182169
183170 return command ;
184171 }
172+
173+ private class ShowWorkloadsInfoAction : SynchronousCommandLineAction
174+ {
175+ public ShowWorkloadsInfoAction ( )
176+ {
177+ Terminating = true ;
178+ }
179+
180+ public override int Invoke ( ParseResult parseResult )
181+ {
182+ ShowWorkloadsInfo ( parseResult ) ;
183+ Reporter . Output . WriteLine ( string . Empty ) ;
184+ return 0 ;
185+ }
186+ }
187+
188+ private class ShowWorkloadsVersionOption : SynchronousCommandLineAction
189+ {
190+ public ShowWorkloadsVersionOption ( )
191+ {
192+ Terminating = true ;
193+ }
194+
195+ public override int Invoke ( ParseResult parseResult )
196+ {
197+ Reporter . Output . WriteLine ( GetWorkloadsVersion ( ) ) ;
198+ Reporter . Output . WriteLine ( string . Empty ) ;
199+ return 0 ;
200+ }
201+ }
185202}
0 commit comments