diff --git a/src/dotnet/commands/dotnet-clean/CleanCommandParser.cs b/src/dotnet/commands/dotnet-clean/CleanCommandParser.cs index dfdc5d1ac..6a2fcf2e9 100644 --- a/src/dotnet/commands/dotnet-clean/CleanCommandParser.cs +++ b/src/dotnet/commands/dotnet-clean/CleanCommandParser.cs @@ -1,27 +1,27 @@ // Copyright (c) .NET Foundation and contributors. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. +using System.Linq; using Microsoft.DotNet.Cli.CommandLine; +using LocalizableStrings = Microsoft.DotNet.Tools.Clean.LocalizableStrings; namespace Microsoft.DotNet.Cli { internal static class CleanCommandParser { public static Command Clean() => - Create.Command("clean", - ".NET Clean Command", - CommonOptions.HelpOption(), - Create.Option("-o|--output", "Directory in which the build outputs have been placed.", - Accept.ExactlyOneArgument - .With(name: "OUTPUT_DIR")), - Create.Option("-f|--framework", "Clean a specific framework.", - Accept.ExactlyOneArgument - .With(name: "FRAMEWORK") - .WithSuggestionsFrom(_ => Suggest.TargetFrameworksFromProjectFile())), - Create.Option("-c|--configuration", - "Clean a specific configuration.", - Accept.ExactlyOneArgument - .With(name: "CONFIGURATION") - .WithSuggestionsFrom("DEBUG", "RELEASE"))); + Create.Command( + "clean", + ".NET Clean Command", + Accept.ZeroOrMoreArguments, + CommonOptions.HelpOption(), + Create.Option("-o|--output", + "Directory in which the build outputs have been placed.", + Accept.ExactlyOneArgument + .With(name: "OUTPUT_DIR") + .ForwardAs(o => $"/p:OutputPath={o.Arguments.Single()}")), + CommonOptions.FrameworkOption(), + CommonOptions.ConfigurationOption(), + CommonOptions.VerbosityOption()); } } \ No newline at end of file diff --git a/src/dotnet/commands/dotnet-clean/Program.cs b/src/dotnet/commands/dotnet-clean/Program.cs index f76e25b84..3d9132ad5 100644 --- a/src/dotnet/commands/dotnet-clean/Program.cs +++ b/src/dotnet/commands/dotnet-clean/Program.cs @@ -19,78 +19,23 @@ namespace Microsoft.DotNet.Tools.Clean public static CleanCommand FromArgs(string[] args, string msbuildPath = null) { - DebugHelper.HandleDebugSwitch(ref args); + var msbuildArgs = new List(); - CommandLineApplication app = new CommandLineApplication(throwOnUnexpectedArg: false) - { - Name = "dotnet clean", - FullName = LocalizableStrings.AppFullName, - Description = LocalizableStrings.AppDescription, - HandleRemainingArguments = true, - ArgumentSeparatorHelpText = HelpMessageStrings.MSBuildAdditionalArgsHelpText - }; - app.HelpOption("-h|--help"); + var parser = Parser.Instance; - CommandArgument projectArgument = app.Argument( - $"<{LocalizableStrings.CmdArgProject}>", - LocalizableStrings.CmdArgProjDescription); + var result = parser.ParseFrom("dotnet clean", args); - CommandOption outputOption = app.Option( - $"-o|--output <{LocalizableStrings.CmdOutputDir}>", - LocalizableStrings.CmdOutputDirDescription, - CommandOptionType.SingleValue); - CommandOption frameworkOption = app.Option( - $"-f|--framework <{LocalizableStrings.CmdFramework}>", - LocalizableStrings.CmdFrameworkDescription, - CommandOptionType.SingleValue); - CommandOption configurationOption = app.Option( - $"-c|--configuration <{LocalizableStrings.CmdConfiguration}>", - LocalizableStrings.CmdConfigurationDescription, - CommandOptionType.SingleValue); - CommandOption verbosityOption = AddVerbosityOption(app); + Reporter.Output.WriteLine(result.Diagram()); - List msbuildArgs = null; - app.OnExecute(() => - { - msbuildArgs = new List(); + result.ShowHelpIfRequested(); - if (!string.IsNullOrEmpty(projectArgument.Value)) - { - msbuildArgs.Add(projectArgument.Value); - } + var parsedClean = result["dotnet"]["clean"]; + + msbuildArgs.Add("/t:Clean"); - msbuildArgs.Add("/t:Clean"); + msbuildArgs.AddRange(appliedBuildOptions.OptionValuesToBeForwarded()); - if (outputOption.HasValue()) - { - msbuildArgs.Add($"/p:OutputPath={outputOption.Value()}"); - } - - if (frameworkOption.HasValue()) - { - msbuildArgs.Add($"/p:TargetFramework={frameworkOption.Value()}"); - } - - if (configurationOption.HasValue()) - { - msbuildArgs.Add($"/p:Configuration={configurationOption.Value()}"); - } - - if (verbosityOption.HasValue()) - { - msbuildArgs.Add($"/verbosity:{verbosityOption.Value()}"); - } - - msbuildArgs.AddRange(app.RemainingArguments); - - return 0; - }); - - int exitCode = app.Execute(args); - if (msbuildArgs == null) - { - throw new CommandCreationException(exitCode); - } + msbuildArgs.AddRange(parsedClean.Arguments); return new CleanCommand(msbuildArgs, msbuildPath); }