commit
07418af874
9 changed files with 65 additions and 4 deletions
|
@ -45,6 +45,7 @@ namespace Microsoft.DotNet.Cli.CommandLine
|
|||
public List<CommandLineApplication> 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<CommandLineApplication> 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(" [[--] <arg>...]]");
|
||||
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()
|
||||
|
|
10
src/dotnet/CommandLine/HelpMessageStrings.cs
Normal file
10
src/dotnet/CommandLine/HelpMessageStrings.cs
Normal file
|
@ -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.";
|
||||
}
|
||||
}
|
|
@ -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("<PROJECT>",
|
||||
|
|
|
@ -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");
|
||||
|
||||
|
|
|
@ -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");
|
||||
|
|
|
@ -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("<PROJECT>",
|
||||
|
|
|
@ -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");
|
||||
|
|
|
@ -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(
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue