restore:captures arguments for forwarding to MSBuild

This commit is contained in:
Jon Sequeira 2017-03-07 16:40:18 -08:00
parent 53ea7f62bf
commit 30480fa189
8 changed files with 88 additions and 36 deletions

View file

@ -2,15 +2,15 @@
// 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; using System;
using System.Linq;
using Microsoft.DotNet.Cli.CommandLine; using Microsoft.DotNet.Cli.CommandLine;
namespace Microsoft.DotNet.Cli namespace Microsoft.DotNet.Cli
{ {
public static class Parser public static class Parser
{ {
public static Command DotnetCommand { get; } = public static CommandLine.Parser Instance { get; } = new CommandLine.Parser(
Create.Command("dotnet", delimiters: Array.Empty<char>(),
options: Create.Command("dotnet",
".NET Command Line Tools", ".NET Command Line Tools",
Accept.NoArguments, Accept.NoArguments,
NewCommandParser.New(), NewCommandParser.New(),
@ -28,10 +28,11 @@ namespace Microsoft.DotNet.Cli
ListCommandParser.List(), ListCommandParser.List(),
NuGetCommandParser.NuGet(), NuGetCommandParser.NuGet(),
Create.Command("msbuild", ""), Create.Command("msbuild", ""),
Create.Command("vstest", ""), CompleteCommandParser.Complete(), Create.Command("vstest", ""),
CompleteCommandParser.Complete(),
CommonOptions.HelpOption(), CommonOptions.HelpOption(),
Create.Option("--info", ""), Create.Option("--info", ""),
CommonOptions.VerbosityOption(), CommonOptions.VerbosityOption(),
Create.Option("-d", "")); Create.Option("-d", "")));
} }
} }

View file

@ -19,7 +19,7 @@ namespace Microsoft.DotNet.Cli
DebugHelper.HandleDebugSwitch(ref args); DebugHelper.HandleDebugSwitch(ref args);
// get the parser for the current subcommand // get the parser for the current subcommand
var parser = Parser.DotnetCommand["complete"]; var parser = Parser.Instance["dotnet"]["complete"];
// parse the arguments // parse the arguments
var result = parser.Parse(args); var result = parser.Parse(args);
@ -62,7 +62,7 @@ namespace Microsoft.DotNet.Cli
} }
} }
var result = Parser.DotnetCommand.Parse(input); var result = Parser.Instance.Parse(input);
return result.Suggestions() return result.Suggestions()
.ToArray(); .ToArray();

View file

@ -22,9 +22,7 @@ namespace Microsoft.DotNet.Tools.Restore
{ {
DebugHelper.HandleDebugSwitch(ref args); DebugHelper.HandleDebugSwitch(ref args);
var parser = new Cli.CommandLine.Parser( var parser = Parser.Instance["dotnet"];
delimiters: Array.Empty<char>(),
options: Parser.DotnetCommand["restore"]);
var result = parser.Parse(args); var result = parser.Parse(args);
@ -40,6 +38,7 @@ namespace Microsoft.DotNet.Tools.Restore
}; };
msbuildArgs.AddRange(restore.ArgsToBeForwarded()); msbuildArgs.AddRange(restore.ArgsToBeForwarded());
msbuildArgs.AddRange(restore.Arguments); msbuildArgs.AddRange(restore.Arguments);
return new RestoreCommand(msbuildArgs, msbuildPath); return new RestoreCommand(msbuildArgs, msbuildPath);

View file

@ -11,7 +11,7 @@ namespace Microsoft.DotNet.Cli
Create.Command( Create.Command(
"restore", "restore",
".NET dependency restorer", ".NET dependency restorer",
Accept.ExactlyOneArgument, Accept.ZeroOrMoreArguments,
CommonOptions.HelpOption(), CommonOptions.HelpOption(),
Create.Option( Create.Option(
"-s|--source", "-s|--source",

View file

@ -40,7 +40,7 @@
<PackageReference Include="Microsoft.Win32.Registry" Version="4.3.0" /> <PackageReference Include="Microsoft.Win32.Registry" Version="4.3.0" />
<PackageReference Include="Microsoft.Build" Version="$(CLI_MSBuild_Version)" /> <PackageReference Include="Microsoft.Build" Version="$(CLI_MSBuild_Version)" />
<PackageReference Include="Microsoft.DotNet.PlatformAbstractions" Version="$(PlatformAbstractionsVersion)" /> <PackageReference Include="Microsoft.DotNet.PlatformAbstractions" Version="$(PlatformAbstractionsVersion)" />
<PackageReference Include="Microsoft.DotNet.Cli.CommandLine" Version="0.1.0-alpha-78" /> <PackageReference Include="Microsoft.DotNet.Cli.CommandLine" Version="0.1.0-alpha-80" />
<PackageReference Include="Microsoft.TemplateEngine.Abstractions" Version="$(TemplateEngineVersion)" /> <PackageReference Include="Microsoft.TemplateEngine.Abstractions" Version="$(TemplateEngineVersion)" />
<PackageReference Include="Microsoft.TemplateEngine.Cli" Version="$(TemplateEngineVersion)" /> <PackageReference Include="Microsoft.TemplateEngine.Cli" Version="$(TemplateEngineVersion)" />
<PackageReference Include="Microsoft.TemplateEngine.Orchestrator.RunnableProjects" Version="$(TemplateEngineVersion)" /> <PackageReference Include="Microsoft.TemplateEngine.Orchestrator.RunnableProjects" Version="$(TemplateEngineVersion)" />

View file

@ -25,7 +25,7 @@ namespace Microsoft.DotNet.Tests.ParserTests
[Fact] [Fact]
public void AddReferenceHasDefaultArgumentSetToCurrentDirectory() public void AddReferenceHasDefaultArgumentSetToCurrentDirectory()
{ {
var command = Parser.DotnetCommand; var command = Parser.Instance;
var result = command.Parse("dotnet add reference my.csproj"); var result = command.Parse("dotnet add reference my.csproj");
@ -41,7 +41,7 @@ namespace Microsoft.DotNet.Tests.ParserTests
[Fact] [Fact]
public void AddReferenceWithoutArgumentResultsInAnError() public void AddReferenceWithoutArgumentResultsInAnError()
{ {
var command = Parser.DotnetCommand; var command = Parser.Instance;
var result = command.Parse("dotnet add reference"); var result = command.Parse("dotnet add reference");

View file

@ -0,0 +1,52 @@
// 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;
using FluentAssertions;
using Microsoft.DotNet.Cli.CommandLine;
using Xunit;
using Xunit.Abstractions;
using Parser = Microsoft.DotNet.Cli.Parser;
namespace Microsoft.DotNet.Tests.ParserTests
{
public class RestoreParserTests
{
private readonly ITestOutputHelper output;
public RestoreParserTests(ITestOutputHelper output)
{
this.output = output;
}
[Fact]
public void RestoreCapturesArgumentsToForwardToMSBuildWhenTargetIsSpecified()
{
var parser = Parser.Instance["dotnet"];
var result = parser.Parse(@"restore .\some.csproj --packages c:\.nuget\packages /p:SkipInvalidConfigurations=true");
output.WriteLine(result.Diagram());
result["restore"]
.Arguments
.Should()
.BeEquivalentTo(@".\some.csproj", @"/p:SkipInvalidConfigurations=true");
}
[Fact]
public void RestoreCapturesArgumentsToForwardToMSBuildWhenTargetIsNotSpecified()
{
var parser = Parser.Instance["dotnet"];
var result = parser.Parse(@"restore --packages c:\.nuget\packages /p:SkipInvalidConfigurations=true");
output.WriteLine(result.Diagram());
result["restore"]
.Arguments
.Should()
.BeEquivalentTo(@"/p:SkipInvalidConfigurations=true");
}
}
}

View file

@ -42,6 +42,6 @@
<PackageReference Include="xunit" Version="2.2.0-beta4-build3444" /> <PackageReference Include="xunit" Version="2.2.0-beta4-build3444" />
<PackageReference Include="xunit.netcore.extensions" Version="1.0.0-prerelease-00206" /> <PackageReference Include="xunit.netcore.extensions" Version="1.0.0-prerelease-00206" />
<PackageReference Include="Microsoft.DotNet.PlatformAbstractions" Version="$(PlatformAbstractionsVersion)" /> <PackageReference Include="Microsoft.DotNet.PlatformAbstractions" Version="$(PlatformAbstractionsVersion)" />
<PackageReference Include="Microsoft.DotNet.Cli.CommandLine" Version="0.1.0-alpha-78" /> <PackageReference Include="Microsoft.DotNet.Cli.CommandLine" Version="0.1.0-alpha-80" />
</ItemGroup> </ItemGroup>
</Project> </Project>