From 59f2483fd31dd5d852dfbd59fa2f70d954eded25 Mon Sep 17 00:00:00 2001 From: Justin Goshi Date: Tue, 11 Oct 2016 17:29:09 -0700 Subject: [PATCH] https://github.com/dotnet/cli/issues/4293 Improve help text for commands that shell out to msbuild. --- .../CommandLine/CommandLineApplication.cs | 11 +++++- src/dotnet/CommandLine/HelpMessageStrings.cs | 10 ++++++ src/dotnet/commands/dotnet-build3/Program.cs | 1 + src/dotnet/commands/dotnet-clean3/Program.cs | 3 +- .../commands/dotnet-pack3/Pack3Command.cs | 4 ++- .../commands/dotnet-publish3/Program.cs | 1 + .../commands/dotnet-restore3/Program.cs | 4 ++- src/dotnet/commands/dotnet-run3/Program.cs | 1 + .../GivenDotnetMSBuildBuildsProjects.cs | 34 +++++++++++++++++++ 9 files changed, 65 insertions(+), 4 deletions(-) create mode 100644 src/dotnet/CommandLine/HelpMessageStrings.cs diff --git a/src/dotnet/CommandLine/CommandLineApplication.cs b/src/dotnet/CommandLine/CommandLineApplication.cs index 334167287..dfcc75fcb 100644 --- a/src/dotnet/CommandLine/CommandLineApplication.cs +++ b/src/dotnet/CommandLine/CommandLineApplication.cs @@ -45,6 +45,7 @@ namespace Microsoft.DotNet.Cli.CommandLine public List Commands { get; private set; } public bool HandleResponseFiles { get; set; } public bool AllowArgumentSeparator { get; set; } + public string ArgumentSeparatorHelpText { get; set; } public CommandLineApplication Command(string name, Action configuration, bool throwOnUnexpectedArg = true) @@ -361,6 +362,7 @@ namespace Microsoft.DotNet.Cli.CommandLine var optionsBuilder = new StringBuilder(); var commandsBuilder = new StringBuilder(); var argumentsBuilder = new StringBuilder(); + var argumentSeparatorBuilder = new StringBuilder(); if (target.Arguments.Any()) { @@ -417,6 +419,13 @@ namespace Microsoft.DotNet.Cli.CommandLine if (target.AllowArgumentSeparator) { headerBuilder.Append(" [[--] ...]]"); + if (!string.IsNullOrEmpty(target.ArgumentSeparatorHelpText)) + { + argumentSeparatorBuilder.AppendLine(); + argumentSeparatorBuilder.AppendLine("Args:"); + argumentSeparatorBuilder.AppendLine($" {target.ArgumentSeparatorHelpText}"); + argumentSeparatorBuilder.AppendLine(); + } } headerBuilder.AppendLine(); @@ -425,7 +434,7 @@ namespace Microsoft.DotNet.Cli.CommandLine nameAndVersion.AppendLine(GetFullNameAndVersion()); nameAndVersion.AppendLine(); - Console.Write("{0}{1}{2}{3}{4}", nameAndVersion, headerBuilder, argumentsBuilder, optionsBuilder, commandsBuilder); + Console.Write("{0}{1}{2}{3}{4}{5}", nameAndVersion, headerBuilder, argumentsBuilder, optionsBuilder, commandsBuilder, argumentSeparatorBuilder); } public void ShowVersion() diff --git a/src/dotnet/CommandLine/HelpMessageStrings.cs b/src/dotnet/CommandLine/HelpMessageStrings.cs new file mode 100644 index 000000000..f9f48def8 --- /dev/null +++ b/src/dotnet/CommandLine/HelpMessageStrings.cs @@ -0,0 +1,10 @@ +// 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. + +namespace Microsoft.DotNet.Cli.CommandLine +{ + internal class HelpMessageStrings + { + internal const string MSBuildAdditionalArgsHelpText = "Any extra options that should be passed to MSBuild. See 'dotnet msbuild -h' for available options."; + } +} diff --git a/src/dotnet/commands/dotnet-build3/Program.cs b/src/dotnet/commands/dotnet-build3/Program.cs index b34a7b56c..8d44f980e 100644 --- a/src/dotnet/commands/dotnet-build3/Program.cs +++ b/src/dotnet/commands/dotnet-build3/Program.cs @@ -19,6 +19,7 @@ namespace Microsoft.DotNet.Tools.Build3 app.FullName = ".NET Builder"; app.Description = "Builder for the .NET Platform. Delegates to the MSBuild 'Build' target in the project file."; app.AllowArgumentSeparator = true; + app.ArgumentSeparatorHelpText = HelpMessageStrings.MSBuildAdditionalArgsHelpText; app.HelpOption("-h|--help"); CommandArgument projectArgument = app.Argument("", diff --git a/src/dotnet/commands/dotnet-clean3/Program.cs b/src/dotnet/commands/dotnet-clean3/Program.cs index f5c2410bf..7824ed9a9 100644 --- a/src/dotnet/commands/dotnet-clean3/Program.cs +++ b/src/dotnet/commands/dotnet-clean3/Program.cs @@ -19,7 +19,8 @@ namespace Microsoft.DotNet.Tools.Clean3 Name = "dotnet clean3", FullName = ".NET Clean Command", Description = "Command to clean previously generated build outputs.", - AllowArgumentSeparator = true + AllowArgumentSeparator = true, + ArgumentSeparatorHelpText = HelpMessageStrings.MSBuildAdditionalArgsHelpText }; app.HelpOption("-h|--help"); diff --git a/src/dotnet/commands/dotnet-pack3/Pack3Command.cs b/src/dotnet/commands/dotnet-pack3/Pack3Command.cs index 8a9d007af..d5faa29d8 100644 --- a/src/dotnet/commands/dotnet-pack3/Pack3Command.cs +++ b/src/dotnet/commands/dotnet-pack3/Pack3Command.cs @@ -18,7 +18,9 @@ namespace Microsoft.DotNet.Tools.Pack3 { Name = "pack3", FullName = "pack3", - Description = "pack for msbuild" + Description = "pack for msbuild", + AllowArgumentSeparator = true, + ArgumentSeparatorHelpText = HelpMessageStrings.MSBuildAdditionalArgsHelpText }; cmd.HelpOption("-h|--help"); diff --git a/src/dotnet/commands/dotnet-publish3/Program.cs b/src/dotnet/commands/dotnet-publish3/Program.cs index 41951d13e..1e84dcd42 100644 --- a/src/dotnet/commands/dotnet-publish3/Program.cs +++ b/src/dotnet/commands/dotnet-publish3/Program.cs @@ -17,6 +17,7 @@ namespace Microsoft.DotNet.Tools.Publish3 app.FullName = ".NET Publisher"; app.Description = "Publisher for the .NET Platform"; app.AllowArgumentSeparator = true; + app.ArgumentSeparatorHelpText = HelpMessageStrings.MSBuildAdditionalArgsHelpText; app.HelpOption("-h|--help"); CommandArgument projectArgument = app.Argument("", diff --git a/src/dotnet/commands/dotnet-restore3/Program.cs b/src/dotnet/commands/dotnet-restore3/Program.cs index 11e8b0332..7a8d5f0af 100644 --- a/src/dotnet/commands/dotnet-restore3/Program.cs +++ b/src/dotnet/commands/dotnet-restore3/Program.cs @@ -18,7 +18,9 @@ namespace Microsoft.DotNet.Tools.Restore3 { Name = "restore3", FullName = "restore3", - Description = "restore for msbuild" + Description = "restore for msbuild", + AllowArgumentSeparator = true, + ArgumentSeparatorHelpText = HelpMessageStrings.MSBuildAdditionalArgsHelpText }; cmd.HelpOption("-h|--help"); diff --git a/src/dotnet/commands/dotnet-run3/Program.cs b/src/dotnet/commands/dotnet-run3/Program.cs index 13c564f3b..843735376 100644 --- a/src/dotnet/commands/dotnet-run3/Program.cs +++ b/src/dotnet/commands/dotnet-run3/Program.cs @@ -19,6 +19,7 @@ namespace Microsoft.DotNet.Tools.Run app.Description = "Command used to run .NET apps"; app.HandleResponseFiles = true; app.AllowArgumentSeparator = true; + app.ArgumentSeparatorHelpText = HelpMessageStrings.MSBuildAdditionalArgsHelpText; app.HelpOption("-h|--help"); CommandOption configuration = app.Option( diff --git a/test/dotnet-msbuild.Tests/GivenDotnetMSBuildBuildsProjects.cs b/test/dotnet-msbuild.Tests/GivenDotnetMSBuildBuildsProjects.cs index e79103b85..f85509e40 100644 --- a/test/dotnet-msbuild.Tests/GivenDotnetMSBuildBuildsProjects.cs +++ b/test/dotnet-msbuild.Tests/GivenDotnetMSBuildBuildsProjects.cs @@ -41,5 +41,39 @@ namespace Microsoft.DotNet.Cli.MSBuild.Tests .And .HaveStdOutContaining("You want me to say 'GreatScott'"); } + + [Theory] + // https://github.com/dotnet/cli/issues/4293 + [InlineData("build", false)] + [InlineData("pack", false)] + [InlineData("publish", false)] + [InlineData("restore", false)] + [InlineData("run", false)] + [InlineData("build3", true)] + [InlineData("clean3", true)] + [InlineData("pack3", true)] + [InlineData("publish3", true)] + [InlineData("restore3", true)] + [InlineData("run3", true)] + public void ItMSBuildHelpText(string commandName, bool isMSBuildCommand) + { + const string MSBuildHelpText = " Any extra options that should be passed to MSBuild. See 'dotnet msbuild -h' for available options."; + + var projectDirectory = TestAssetsManager.CreateTestDirectory("ItContainsMSBuildHelpText"); + var result = new TestCommand("dotnet") + .WithWorkingDirectory(projectDirectory.Path) + .ExecuteWithCapturedOutput($"{commandName} --help"); + + result.ExitCode.Should().Be(0); + if (isMSBuildCommand) + { + result.StdOut.Should().Contain(MSBuildHelpText); + } + else + { + result.StdOut.Should().NotContain(MSBuildHelpText); + } + } + } }