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,36 +2,37 @@
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System;
using System.Linq;
using Microsoft.DotNet.Cli.CommandLine;
namespace Microsoft.DotNet.Cli
{
public static class Parser
{
public static Command DotnetCommand { get; } =
Create.Command("dotnet",
".NET Command Line Tools",
Accept.NoArguments,
NewCommandParser.New(),
RestoreCommandParser.Restore(),
BuildCommandParser.Build(),
PublishCommandParser.Publish(),
RunCommandParser.Run(),
TestCommandParser.Test(),
PackCommandParser.Pack(),
MigrateCommandParser.Migrate(),
CleanCommandParser.Clean(),
SlnCommandParser.Sln(),
AddCommandParser.Add(),
RemoveCommandParser.Remove(),
ListCommandParser.List(),
NuGetCommandParser.NuGet(),
Create.Command("msbuild", ""),
Create.Command("vstest", ""), CompleteCommandParser.Complete(),
CommonOptions.HelpOption(),
Create.Option("--info", ""),
CommonOptions.VerbosityOption(),
Create.Option("-d", ""));
public static CommandLine.Parser Instance { get; } = new CommandLine.Parser(
delimiters: Array.Empty<char>(),
options: Create.Command("dotnet",
".NET Command Line Tools",
Accept.NoArguments,
NewCommandParser.New(),
RestoreCommandParser.Restore(),
BuildCommandParser.Build(),
PublishCommandParser.Publish(),
RunCommandParser.Run(),
TestCommandParser.Test(),
PackCommandParser.Pack(),
MigrateCommandParser.Migrate(),
CleanCommandParser.Clean(),
SlnCommandParser.Sln(),
AddCommandParser.Add(),
RemoveCommandParser.Remove(),
ListCommandParser.List(),
NuGetCommandParser.NuGet(),
Create.Command("msbuild", ""),
Create.Command("vstest", ""),
CompleteCommandParser.Complete(),
CommonOptions.HelpOption(),
Create.Option("--info", ""),
CommonOptions.VerbosityOption(),
Create.Option("-d", "")));
}
}

View file

@ -19,7 +19,7 @@ namespace Microsoft.DotNet.Cli
DebugHelper.HandleDebugSwitch(ref args);
// get the parser for the current subcommand
var parser = Parser.DotnetCommand["complete"];
var parser = Parser.Instance["dotnet"]["complete"];
// parse the arguments
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()
.ToArray();

View file

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

View file

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

View file

@ -40,7 +40,7 @@
<PackageReference Include="Microsoft.Win32.Registry" Version="4.3.0" />
<PackageReference Include="Microsoft.Build" Version="$(CLI_MSBuild_Version)" />
<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.Cli" Version="$(TemplateEngineVersion)" />
<PackageReference Include="Microsoft.TemplateEngine.Orchestrator.RunnableProjects" Version="$(TemplateEngineVersion)" />

View file

@ -25,7 +25,7 @@ namespace Microsoft.DotNet.Tests.ParserTests
[Fact]
public void AddReferenceHasDefaultArgumentSetToCurrentDirectory()
{
var command = Parser.DotnetCommand;
var command = Parser.Instance;
var result = command.Parse("dotnet add reference my.csproj");
@ -41,7 +41,7 @@ namespace Microsoft.DotNet.Tests.ParserTests
[Fact]
public void AddReferenceWithoutArgumentResultsInAnError()
{
var command = Parser.DotnetCommand;
var command = Parser.Instance;
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.netcore.extensions" Version="1.0.0-prerelease-00206" />
<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>
</Project>