publish using new parser, rename ArgsToBeForwarded

This commit is contained in:
jonsequitur 2017-03-09 07:35:06 -08:00
parent 1a0ba24883
commit 0b94c979db
9 changed files with 70 additions and 21 deletions

View file

@ -19,7 +19,7 @@ namespace Microsoft.DotNet.Cli
rule.MaterializeAs(o => rule.MaterializeAs(o =>
new ForwardedArgument(format(o))); new ForwardedArgument(format(o)));
public static IEnumerable<string> ArgsToBeForwarded( public static IEnumerable<string> OptionValuesToBeForwarded(
this AppliedOption command) => this AppliedOption command) =>
command.AppliedOptions command.AppliedOptions
.Select(o => o.Value()) .Select(o => o.Value())

View file

@ -17,7 +17,8 @@ namespace Microsoft.DotNet.Cli
Create.Option( Create.Option(
"-v|--verbosity", "-v|--verbosity",
"Set the verbosity level of the command. Allowed values are q[uiet], m[inimal], n[ormal], d[etailed], and diag[nostic]", "Set the verbosity level of the command. Allowed values are q[uiet], m[inimal], n[ormal], d[etailed], and diag[nostic]",
Accept.AnyOneOf("q", "quiet", Accept.AnyOneOf(
"q", "quiet",
"m", "minimal", "m", "minimal",
"n", "normal", "n", "normal",
"d", "detailed") "d", "detailed")

View file

@ -32,7 +32,6 @@ namespace Microsoft.DotNet.Cli
CompleteCommandParser.Complete(), CompleteCommandParser.Complete(),
CommonOptions.HelpOption(), CommonOptions.HelpOption(),
Create.Option("--info", ""), Create.Option("--info", ""),
CommonOptions.VerbosityOption(),
Create.Option("-d", ""))); Create.Option("-d", "")));
} }
} }

View file

@ -84,6 +84,12 @@ namespace Microsoft.DotNet.Cli
return 1; return 1;
} }
catch (Exception e) when (!e.ShouldBeDisplayedAsError())
{
Reporter.Output.WriteLine(e.ToString().Red().Bold());
return 1;
}
finally finally
{ {
if (PerfTrace.Enabled) if (PerfTrace.Enabled)

View file

@ -8,7 +8,7 @@ using Microsoft.DotNet.Tools.MSBuild;
namespace Microsoft.DotNet.Tools.Publish namespace Microsoft.DotNet.Tools.Publish
{ {
public partial class PublishCommand : MSBuildForwardingApp public class PublishCommand : MSBuildForwardingApp
{ {
private PublishCommand(IEnumerable<string> msbuildArgs, string msbuildPath = null) private PublishCommand(IEnumerable<string> msbuildArgs, string msbuildPath = null)
: base(msbuildArgs, msbuildPath) : base(msbuildArgs, msbuildPath)
@ -27,12 +27,12 @@ namespace Microsoft.DotNet.Tools.Publish
msbuildArgs.Add("/t:Publish"); msbuildArgs.Add("/t:Publish");
var appliedPublishOption = result.AppliedOptions["publish"]; var appliedPublishOption = result["dotnet"]["publish"];
msbuildArgs.AddRange(appliedPublishOption.OptionValuesToBeForwarded());
msbuildArgs.AddRange(appliedPublishOption.Arguments); msbuildArgs.AddRange(appliedPublishOption.Arguments);
msbuildArgs.AddRange(appliedPublishOption.ArgsToBeForwarded());
return new PublishCommand(msbuildArgs, msbuildPath); return new PublishCommand(msbuildArgs, msbuildPath);
} }

View file

@ -14,12 +14,12 @@ namespace Microsoft.DotNet.Cli
CommonOptions.HelpOption(), CommonOptions.HelpOption(),
Create.Option("-f|--framework", Create.Option("-f|--framework",
"Target framework to publish for. The target framework has to be specified in the project file.", "Target framework to publish for. The target framework has to be specified in the project file.",
Accept.AnyOneOf(Suggest.TargetFrameworksFromProjectFile) Accept.WithSuggestionsFrom(_ => Suggest.TargetFrameworksFromProjectFile())
.With(name: "FRAMEWORK") .With(name: "FRAMEWORK")
.ForwardAs("/p:TargetFramework={0}")), .ForwardAs("/p:TargetFramework={0}")),
Create.Option("-r|--runtime", Create.Option("-r|--runtime",
"Publish the project for a given runtime. This is used when creating self-contained deployment. Default is to publish a framework-dependent app.", "Publish the project for a given runtime. This is used when creating self-contained deployment. Default is to publish a framework-dependent app.",
Accept.AnyOneOf(Suggest.RunTimesFromProjectFile) Accept.WithSuggestionsFrom(_ => Suggest.RunTimesFromProjectFile())
.With(name: "RUNTIME_IDENTIFIER") .With(name: "RUNTIME_IDENTIFIER")
.ForwardAs("/p:RuntimeIdentifier={0}")), .ForwardAs("/p:RuntimeIdentifier={0}")),
Create.Option("-o|--output", Create.Option("-o|--output",

View file

@ -23,13 +23,15 @@ namespace Microsoft.DotNet.Tools.Restore
{ {
DebugHelper.HandleDebugSwitch(ref args); DebugHelper.HandleDebugSwitch(ref args);
Reporter.Output.WriteLine(string.Join(" ", args));
var parser = Parser.Instance; var parser = Parser.Instance;
var result = parser.ParseFrom("dotnet restore", args); var result = parser.ParseFrom("dotnet restore", args);
Reporter.Verbose.WriteLine(result.Diagram()); Reporter.Output.WriteLine(result.Diagram());
var restore = result["restore"]; var restore = result["dotnet"]["restore"];
var msbuildArgs = new List<string> var msbuildArgs = new List<string>
{ {
@ -38,7 +40,7 @@ namespace Microsoft.DotNet.Tools.Restore
"/ConsoleLoggerParameters:Verbosity=Minimal" "/ConsoleLoggerParameters:Verbosity=Minimal"
}; };
msbuildArgs.AddRange(restore.ArgsToBeForwarded()); msbuildArgs.AddRange(restore.OptionValuesToBeForwarded());
msbuildArgs.AddRange(restore.Arguments); msbuildArgs.AddRange(restore.Arguments);

View file

@ -1,16 +1,25 @@
// 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 Microsoft.DotNet.Tools.Publish;
using FluentAssertions;
using Xunit;
using System; using System;
using FluentAssertions;
using System.Linq; using System.Linq;
using Microsoft.DotNet.Cli.CommandLine;
using Microsoft.DotNet.Tools.Publish;
using Xunit;
using Xunit.Abstractions;
namespace Microsoft.DotNet.Cli.MSBuild.Tests namespace Microsoft.DotNet.Cli.MSBuild.Tests
{ {
public class GivenDotnetPublishInvocation public class GivenDotnetPublishInvocation
{ {
private readonly ITestOutputHelper output;
public GivenDotnetPublishInvocation(ITestOutputHelper output)
{
this.output = output;
}
const string ExpectedPrefix = "exec <msbuildpath> /m /v:m /t:Publish"; const string ExpectedPrefix = "exec <msbuildpath> /m /v:m /t:Publish";
[Theory] [Theory]
@ -25,8 +34,8 @@ namespace Microsoft.DotNet.Cli.MSBuild.Tests
[InlineData(new string[] { "--configuration", "<configuration>" }, "/p:Configuration=<configuration>")] [InlineData(new string[] { "--configuration", "<configuration>" }, "/p:Configuration=<configuration>")]
[InlineData(new string[] { "--version-suffix", "<version-suffix>" }, "/p:VersionSuffix=<version-suffix>")] [InlineData(new string[] { "--version-suffix", "<version-suffix>" }, "/p:VersionSuffix=<version-suffix>")]
[InlineData(new string[] { "--filter", "<filter>" }, "/p:FilterProjectFiles=<filter>")] [InlineData(new string[] { "--filter", "<filter>" }, "/p:FilterProjectFiles=<filter>")]
[InlineData(new string[] { "-v", "<verbosity>" }, "/verbosity:<verbosity>")] [InlineData(new string[] { "-v", "minimal" }, "/verbosity:minimal")]
[InlineData(new string[] { "--verbosity", "<verbosity>" }, "/verbosity:<verbosity>")] [InlineData(new string[] { "--verbosity", "minimal" }, "/verbosity:minimal")]
[InlineData(new string[] { "<project>" }, "<project>")] [InlineData(new string[] { "<project>" }, "<project>")]
[InlineData(new string[] { "<project>", "<extra-args>" }, "<project> <extra-args>")] [InlineData(new string[] { "<project>", "<extra-args>" }, "<project> <extra-args>")]
public void MsbuildInvocationIsCorrect(string[] args, string expectedAdditionalArgs) public void MsbuildInvocationIsCorrect(string[] args, string expectedAdditionalArgs)
@ -35,7 +44,39 @@ namespace Microsoft.DotNet.Cli.MSBuild.Tests
var msbuildPath = "<msbuildpath>"; var msbuildPath = "<msbuildpath>";
PublishCommand.FromArgs(args, msbuildPath) PublishCommand.FromArgs(args, msbuildPath)
.GetProcessStartInfo().Arguments.Should().Be($"{ExpectedPrefix}{expectedAdditionalArgs}"); .GetProcessStartInfo()
.Arguments.Should()
.Be($"{ExpectedPrefix}{expectedAdditionalArgs}");
}
[Theory]
[InlineData(new string[] { }, "")]
[InlineData(new string[] { "-f", "<framework>" }, "/p:TargetFramework=<framework>")]
[InlineData(new string[] { "--framework", "<framework>" }, "/p:TargetFramework=<framework>")]
[InlineData(new string[] { "-r", "<runtime>" }, "/p:RuntimeIdentifier=<runtime>")]
[InlineData(new string[] { "--runtime", "<runtime>" }, "/p:RuntimeIdentifier=<runtime>")]
[InlineData(new string[] { "-o", "<output>" }, "/p:PublishDir=<output>")]
[InlineData(new string[] { "--output", "<output>" }, "/p:PublishDir=<output>")]
[InlineData(new string[] { "-c", "<configuration>" }, "/p:Configuration=<configuration>")]
[InlineData(new string[] { "--configuration", "<configuration>" }, "/p:Configuration=<configuration>")]
[InlineData(new string[] { "--version-suffix", "<version-suffix>" }, "/p:VersionSuffix=<version-suffix>")]
[InlineData(new string[] { "--filter", "<filter>" }, "/p:FilterProjectFiles=<filter>")]
[InlineData(new string[] { "-v", "minimal" }, "/verbosity:minimal")]
[InlineData(new string[] { "--verbosity", "minimal" }, "/verbosity:minimal")]
public void OptionForwardingIsCorrect(string[] args, string expectedAdditionalArgs)
{
var expectedArgs = expectedAdditionalArgs.Split(' ', StringSplitOptions.RemoveEmptyEntries);
var parser = Parser.Instance;
var result = parser.ParseFrom("dotnet publish", args);
output.WriteLine(result.Diagram());
result["dotnet"]["publish"]
.OptionValuesToBeForwarded()
.Should()
.BeEquivalentTo(expectedArgs);
} }
} }
} }

View file

@ -24,7 +24,7 @@ namespace Microsoft.DotNet.Tests.ParserTests
var result = command.Parse("the-command -t argument-two-value -o 123"); var result = command.Parse("the-command -t argument-two-value -o 123");
result["the-command"] result["the-command"]
.ArgsToBeForwarded() .OptionValuesToBeForwarded()
.Should() .Should()
.BeEquivalentTo("/i:123", "/s:argument-two-value"); .BeEquivalentTo("/i:123", "/s:argument-two-value");
} }
@ -39,7 +39,7 @@ namespace Microsoft.DotNet.Tests.ParserTests
var result = command.Parse("the-command -x one -x two"); var result = command.Parse("the-command -x one -x two");
result["the-command"] result["the-command"]
.ArgsToBeForwarded() .OptionValuesToBeForwarded()
.Should() .Should()
.BeEquivalentTo("/x:one&two"); .BeEquivalentTo("/x:one&two");
} }