Clean
This commit is contained in:
parent
c68aba4f63
commit
ca9268c504
2 changed files with 25 additions and 80 deletions
|
@ -1,27 +1,27 @@
|
||||||
// Copyright (c) .NET Foundation and contributors. All rights reserved.
|
// 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.
|
// 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 Microsoft.DotNet.Cli.CommandLine;
|
||||||
|
using LocalizableStrings = Microsoft.DotNet.Tools.Clean.LocalizableStrings;
|
||||||
|
|
||||||
namespace Microsoft.DotNet.Cli
|
namespace Microsoft.DotNet.Cli
|
||||||
{
|
{
|
||||||
internal static class CleanCommandParser
|
internal static class CleanCommandParser
|
||||||
{
|
{
|
||||||
public static Command Clean() =>
|
public static Command Clean() =>
|
||||||
Create.Command("clean",
|
Create.Command(
|
||||||
|
"clean",
|
||||||
".NET Clean Command",
|
".NET Clean Command",
|
||||||
|
Accept.ZeroOrMoreArguments,
|
||||||
CommonOptions.HelpOption(),
|
CommonOptions.HelpOption(),
|
||||||
Create.Option("-o|--output", "Directory in which the build outputs have been placed.",
|
Create.Option("-o|--output",
|
||||||
|
"Directory in which the build outputs have been placed.",
|
||||||
Accept.ExactlyOneArgument
|
Accept.ExactlyOneArgument
|
||||||
.With(name: "OUTPUT_DIR")),
|
.With(name: "OUTPUT_DIR")
|
||||||
Create.Option("-f|--framework", "Clean a specific framework.",
|
.ForwardAs(o => $"/p:OutputPath={o.Arguments.Single()}")),
|
||||||
Accept.ExactlyOneArgument
|
CommonOptions.FrameworkOption(),
|
||||||
.With(name: "FRAMEWORK")
|
CommonOptions.ConfigurationOption(),
|
||||||
.WithSuggestionsFrom(_ => Suggest.TargetFrameworksFromProjectFile())),
|
CommonOptions.VerbosityOption());
|
||||||
Create.Option("-c|--configuration",
|
|
||||||
"Clean a specific configuration.",
|
|
||||||
Accept.ExactlyOneArgument
|
|
||||||
.With(name: "CONFIGURATION")
|
|
||||||
.WithSuggestionsFrom("DEBUG", "RELEASE")));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -19,78 +19,23 @@ namespace Microsoft.DotNet.Tools.Clean
|
||||||
|
|
||||||
public static CleanCommand FromArgs(string[] args, string msbuildPath = null)
|
public static CleanCommand FromArgs(string[] args, string msbuildPath = null)
|
||||||
{
|
{
|
||||||
DebugHelper.HandleDebugSwitch(ref args);
|
var msbuildArgs = new List<string>();
|
||||||
|
|
||||||
CommandLineApplication app = new CommandLineApplication(throwOnUnexpectedArg: false)
|
var parser = Parser.Instance;
|
||||||
{
|
|
||||||
Name = "dotnet clean",
|
|
||||||
FullName = LocalizableStrings.AppFullName,
|
|
||||||
Description = LocalizableStrings.AppDescription,
|
|
||||||
HandleRemainingArguments = true,
|
|
||||||
ArgumentSeparatorHelpText = HelpMessageStrings.MSBuildAdditionalArgsHelpText
|
|
||||||
};
|
|
||||||
app.HelpOption("-h|--help");
|
|
||||||
|
|
||||||
CommandArgument projectArgument = app.Argument(
|
var result = parser.ParseFrom("dotnet clean", args);
|
||||||
$"<{LocalizableStrings.CmdArgProject}>",
|
|
||||||
LocalizableStrings.CmdArgProjDescription);
|
|
||||||
|
|
||||||
CommandOption outputOption = app.Option(
|
Reporter.Output.WriteLine(result.Diagram());
|
||||||
$"-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);
|
|
||||||
|
|
||||||
List<string> msbuildArgs = null;
|
result.ShowHelpIfRequested();
|
||||||
app.OnExecute(() =>
|
|
||||||
{
|
|
||||||
msbuildArgs = new List<string>();
|
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(projectArgument.Value))
|
var parsedClean = result["dotnet"]["clean"];
|
||||||
{
|
|
||||||
msbuildArgs.Add(projectArgument.Value);
|
|
||||||
}
|
|
||||||
|
|
||||||
msbuildArgs.Add("/t:Clean");
|
msbuildArgs.Add("/t:Clean");
|
||||||
|
|
||||||
if (outputOption.HasValue())
|
msbuildArgs.AddRange(appliedBuildOptions.OptionValuesToBeForwarded());
|
||||||
{
|
|
||||||
msbuildArgs.Add($"/p:OutputPath={outputOption.Value()}");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (frameworkOption.HasValue())
|
msbuildArgs.AddRange(parsedClean.Arguments);
|
||||||
{
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
return new CleanCommand(msbuildArgs, msbuildPath);
|
return new CleanCommand(msbuildArgs, msbuildPath);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue