|
21 | 21 | using Microsoft.TemplateEngine.Cli.Commands;
|
22 | 22 | using IReporter = Microsoft.DotNet.Cli.Utils.IReporter;
|
23 | 23 | using Command = System.CommandLine.Command;
|
| 24 | +using System.CommandLine.Invocation; |
24 | 25 |
|
25 | 26 | namespace Microsoft.DotNet.Cli.Commands.Workload;
|
26 | 27 |
|
27 | 28 | internal static class WorkloadCommandParser
|
28 | 29 | {
|
29 | 30 | public static readonly string DocsLink = "https://aka.ms/dotnet-workload";
|
30 |
| - |
31 | 31 | public static readonly Option<bool> InfoOption = new("--info")
|
32 | 32 | {
|
33 | 33 | Description = CliCommandStrings.WorkloadInfoDescription,
|
34 |
| - Arity = ArgumentArity.Zero |
| 34 | + Arity = ArgumentArity.Zero, |
| 35 | + Action = new ShowWorkloadsInfoAction() |
35 | 36 | };
|
36 | 37 |
|
37 | 38 | public static readonly Option<bool> VersionOption = new("--version")
|
38 | 39 | {
|
39 | 40 | Description = CliCommandStrings.WorkloadVersionDescription,
|
40 |
| - Arity = ArgumentArity.Zero |
| 41 | + Arity = ArgumentArity.Zero, |
| 42 | + Action = new ShowWorkloadsVersionOption() |
41 | 43 | };
|
42 | 44 |
|
43 | 45 | public static Command GetCommand()
|
@@ -78,11 +80,11 @@ void WriteUpdateModeAndAnyError(string indent = "")
|
78 | 80 | reporter.WriteLine(indent + CliCommandStrings.ShouldInstallAWorkloadSet);
|
79 | 81 | }
|
80 | 82 | }
|
81 |
| - |
| 83 | + |
82 | 84 | if (showVersion)
|
83 | 85 | {
|
84 | 86 | reporter.WriteLine($" Workload version: {GetWorkloadsVersion()}");
|
85 |
| - |
| 87 | + |
86 | 88 | WriteUpdateModeAndAnyError(indent: " ");
|
87 | 89 | reporter.WriteLine();
|
88 | 90 | }
|
@@ -134,22 +136,7 @@ void WriteUpdateModeAndAnyError(string indent = "")
|
134 | 136 | }
|
135 | 137 | }
|
136 | 138 |
|
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(); |
153 | 140 |
|
154 | 141 | private static Command ConstructCommand()
|
155 | 142 | {
|
@@ -182,4 +169,34 @@ private static Command ConstructCommand()
|
182 | 169 |
|
183 | 170 | return command;
|
184 | 171 | }
|
| 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 | + } |
185 | 202 | }
|
0 commit comments