Initial Cache parser
This commit is contained in:
parent
3ebdf2909d
commit
e0da3090e6
4 changed files with 75 additions and 99 deletions
|
@ -27,6 +27,7 @@ namespace Microsoft.DotNet.Cli
|
||||||
RemoveCommandParser.Remove(),
|
RemoveCommandParser.Remove(),
|
||||||
ListCommandParser.List(),
|
ListCommandParser.List(),
|
||||||
NuGetCommandParser.NuGet(),
|
NuGetCommandParser.NuGet(),
|
||||||
|
CacheCommandParser.Cache(),
|
||||||
Create.Command("msbuild", ""),
|
Create.Command("msbuild", ""),
|
||||||
Create.Command("vstest", ""),
|
Create.Command("vstest", ""),
|
||||||
CompleteCommandParser.Complete(),
|
CompleteCommandParser.Complete(),
|
||||||
|
|
57
src/dotnet/commands/dotnet-cache/CacheCommandParser.cs
Normal file
57
src/dotnet/commands/dotnet-cache/CacheCommandParser.cs
Normal file
|
@ -0,0 +1,57 @@
|
||||||
|
// 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 Microsoft.DotNet.Tools.Cache;
|
||||||
|
|
||||||
|
namespace Microsoft.DotNet.Cli
|
||||||
|
{
|
||||||
|
internal static class CacheCommandParser
|
||||||
|
{
|
||||||
|
public static Command Cache() =>
|
||||||
|
Create.Command(
|
||||||
|
LocalizableStrings.AppFullName,
|
||||||
|
LocalizableStrings.AppDescription,
|
||||||
|
Accept.ZeroOrMoreArguments,
|
||||||
|
CommonOptions.HelpOption(),
|
||||||
|
Create.Option(
|
||||||
|
"-e|--entries",
|
||||||
|
LocalizableStrings.ProjectEntryDescription,
|
||||||
|
Accept.ExactlyOneArgument
|
||||||
|
.With(name: LocalizableStrings.ProjectEntries)
|
||||||
|
.Forward()),
|
||||||
|
CommonOptions.FrameworkOption(),
|
||||||
|
Create.Option(
|
||||||
|
"--framework-version",
|
||||||
|
LocalizableStrings.FrameworkVersionOptionDescription,
|
||||||
|
Accept.ExactlyOneArgument
|
||||||
|
.With(name: LocalizableStrings.FrameworkVersionOption)
|
||||||
|
.ForwardAs(o => $"/p:FX_Version={o.Arguments.Single()}")),
|
||||||
|
CommonOptions.RuntimeOption(),
|
||||||
|
CommonOptions.ConfigurationOption(),
|
||||||
|
Create.Option(
|
||||||
|
"-o|--output",
|
||||||
|
LocalizableStrings.OutputOptionDescription,
|
||||||
|
Accept.ExactlyOneArgument
|
||||||
|
.With(name: LocalizableStrings.OutputOption)
|
||||||
|
.ForwardAs(o => $"/p:ComposeDir={o.Arguments.Single()}")),
|
||||||
|
Create.Option(
|
||||||
|
"-w |--working-dir",
|
||||||
|
LocalizableStrings.IntermediateWorkingDirOptionDescription,
|
||||||
|
Accept.ExactlyOneArgument
|
||||||
|
.With(name: LocalizableStrings.IntermediateWorkingDirOption)
|
||||||
|
.ForwardAs(o => $"/p:ComposeWorkingDir={o.Arguments.Single()}")),
|
||||||
|
Create.Option(
|
||||||
|
"--preserve-working-dir",
|
||||||
|
LocalizableStrings.PreserveIntermediateWorkingDirOptionDescription,
|
||||||
|
Accept.NoArguments
|
||||||
|
.ForwardAs(o => $"/p:PreserveComposeWorkingDir=true")),
|
||||||
|
Create.Option(
|
||||||
|
"--skip-optimization",
|
||||||
|
LocalizableStrings.SkipOptimizationOptionDescription,
|
||||||
|
Accept.NoArguments
|
||||||
|
.ForwardAs("/p:SkipOptimization=true")),
|
||||||
|
CommonOptions.VerbosityOption());
|
||||||
|
}
|
||||||
|
}
|
|
@ -9,7 +9,7 @@ namespace Microsoft.DotNet.Tools.Cache
|
||||||
|
|
||||||
public const string AppDescription = "Caches the specified assemblies for the .NET Platform. By default, these will be optimized for the target runtime and framework.";
|
public const string AppDescription = "Caches the specified assemblies for the .NET Platform. By default, these will be optimized for the target runtime and framework.";
|
||||||
|
|
||||||
public const string ProjectEntries = "ProjectEntries";
|
public const string ProjectEntries = "PROJECT_ENTRIES";
|
||||||
|
|
||||||
public const string ProjectEntryDescription = "The XML file that contains the list of packages to be cached.";
|
public const string ProjectEntryDescription = "The XML file that contains the list of packages to be cached.";
|
||||||
|
|
||||||
|
|
|
@ -23,112 +23,30 @@ namespace Microsoft.DotNet.Tools.Cache
|
||||||
{
|
{
|
||||||
DebugHelper.HandleDebugSwitch(ref args);
|
DebugHelper.HandleDebugSwitch(ref args);
|
||||||
|
|
||||||
var app = new CommandLineApplication(throwOnUnexpectedArg: false);
|
var msbuildArgs = new List<string>();
|
||||||
app.Name = "dotnet cache";
|
|
||||||
app.FullName = LocalizableStrings.AppFullName;
|
|
||||||
app.Description = LocalizableStrings.AppDescription;
|
|
||||||
app.AllowArgumentSeparator = true;
|
|
||||||
app.ArgumentSeparatorHelpText = HelpMessageStrings.MSBuildAdditionalArgsHelpText;
|
|
||||||
app.HelpOption("-h|--help");
|
|
||||||
|
|
||||||
CommandOption projectArgument = app.Option(
|
var parser = Parser.Instance;
|
||||||
$"-e|--entries <{LocalizableStrings.ProjectEntries}>", LocalizableStrings.ProjectEntryDescription,
|
|
||||||
CommandOptionType.SingleValue);
|
|
||||||
|
|
||||||
CommandOption frameworkOption = app.Option(
|
var result = parser.ParseFrom("dotnet cache", args);
|
||||||
$"-f|--framework <{LocalizableStrings.FrameworkOption}>", LocalizableStrings.FrameworkOptionDescription,
|
|
||||||
CommandOptionType.SingleValue);
|
|
||||||
|
|
||||||
CommandOption runtimeOption = app.Option(
|
Reporter.Output.WriteLine(result.Diagram());
|
||||||
$"-r|--runtime <{LocalizableStrings.RuntimeOption}>", LocalizableStrings.RuntimeOptionDescription,
|
|
||||||
CommandOptionType.SingleValue);
|
|
||||||
|
|
||||||
CommandOption outputOption = app.Option(
|
result.ShowHelpIfRequested();
|
||||||
$"-o|--output <{LocalizableStrings.OutputOption}>", LocalizableStrings.OutputOptionDescription,
|
|
||||||
CommandOptionType.SingleValue);
|
|
||||||
|
|
||||||
CommandOption fxOption = app.Option(
|
var appliedBuildOptions = result["dotnet"]["cache"];
|
||||||
$"--framework-version <{LocalizableStrings.FrameworkVersionOption}>", LocalizableStrings.FrameworkVersionOptionDescription,
|
|
||||||
CommandOptionType.SingleValue);
|
|
||||||
|
|
||||||
CommandOption skipOptimizationOption = app.Option(
|
if (!result.HasOption("-e"))
|
||||||
$"--skip-optimization", LocalizableStrings.SkipOptimizationOptionDescription,
|
|
||||||
CommandOptionType.NoValue);
|
|
||||||
|
|
||||||
CommandOption workingDir = app.Option(
|
|
||||||
$"-w |--working-dir <{LocalizableStrings.IntermediateWorkingDirOption}>", LocalizableStrings.IntermediateWorkingDirOptionDescription,
|
|
||||||
CommandOptionType.SingleValue);
|
|
||||||
|
|
||||||
CommandOption preserveWorkingDir = app.Option(
|
|
||||||
$"--preserve-working-dir", LocalizableStrings.PreserveIntermediateWorkingDirOptionDescription,
|
|
||||||
CommandOptionType.NoValue);
|
|
||||||
|
|
||||||
CommandOption verbosityOption = MSBuildForwardingApp.AddVerbosityOption(app);
|
|
||||||
|
|
||||||
List<string> msbuildArgs = null;
|
|
||||||
app.OnExecute(() =>
|
|
||||||
{
|
|
||||||
msbuildArgs = new List<string>();
|
|
||||||
|
|
||||||
if (string.IsNullOrEmpty(projectArgument.Value()))
|
|
||||||
{
|
{
|
||||||
throw new InvalidOperationException(LocalizableStrings.SpecifyEntries);
|
throw new InvalidOperationException(LocalizableStrings.SpecifyEntries);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var msbuildArgs = msbuildArgs = new List<string>();
|
||||||
|
|
||||||
msbuildArgs.Add("/t:ComposeCache");
|
msbuildArgs.Add("/t:ComposeCache");
|
||||||
msbuildArgs.Add(projectArgument.Value());
|
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(frameworkOption.Value()))
|
msbuildArgs.AddRange(appliedBuildOptions.OptionValuesToBeForwarded());
|
||||||
{
|
|
||||||
msbuildArgs.Add($"/p:TargetFramework={frameworkOption.Value()}");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(runtimeOption.Value()))
|
msbuildArgs.AddRange(appliedBuildOptions.Arguments);
|
||||||
{
|
|
||||||
msbuildArgs.Add($"/p:RuntimeIdentifier={runtimeOption.Value()}");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(outputOption.Value()))
|
|
||||||
{
|
|
||||||
var outputPath = Path.GetFullPath(outputOption.Value());
|
|
||||||
msbuildArgs.Add($"/p:ComposeDir={outputPath}");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(fxOption.Value()))
|
|
||||||
{
|
|
||||||
msbuildArgs.Add($"/p:FX_Version={fxOption.Value()}");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(workingDir.Value()))
|
|
||||||
{
|
|
||||||
msbuildArgs.Add($"/p:ComposeWorkingDir={workingDir.Value()}");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (skipOptimizationOption.HasValue())
|
|
||||||
{
|
|
||||||
msbuildArgs.Add($"/p:SkipOptimization={skipOptimizationOption.HasValue()}");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (preserveWorkingDir.HasValue())
|
|
||||||
{
|
|
||||||
msbuildArgs.Add($"/p:PreserveComposeWorkingDir={preserveWorkingDir.HasValue()}");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(verbosityOption.Value()))
|
|
||||||
{
|
|
||||||
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 CacheCommand(msbuildArgs, msbuildPath);
|
return new CacheCommand(msbuildArgs, msbuildPath);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue