Merge pull request #6128 from jonsequitur/fix-subcommand-help-regression
check for help in DotNetTopLevelCommandBase
This commit is contained in:
commit
87527c2e05
3 changed files with 59 additions and 8 deletions
|
@ -28,6 +28,8 @@ namespace Microsoft.DotNet.Cli
|
||||||
|
|
||||||
ParseResult = parser.ParseFrom($"dotnet {CommandName}", args);
|
ParseResult = parser.ParseFrom($"dotnet {CommandName}", args);
|
||||||
|
|
||||||
|
ParseResult.ShowHelpIfRequested();
|
||||||
|
|
||||||
var subcommandName = ParseResult.Command().Name;
|
var subcommandName = ParseResult.Command().Name;
|
||||||
|
|
||||||
try
|
try
|
||||||
|
|
|
@ -14,15 +14,7 @@ namespace Microsoft.DotNet.Cli
|
||||||
|
|
||||||
public static void ShowHelpOrErrorIfAppropriate(this ParseResult parseResult)
|
public static void ShowHelpOrErrorIfAppropriate(this ParseResult parseResult)
|
||||||
{
|
{
|
||||||
var appliedCommand = parseResult.AppliedCommand();
|
parseResult.ShowHelpIfRequested();
|
||||||
|
|
||||||
if (appliedCommand.HasOption("help") ||
|
|
||||||
appliedCommand.Arguments.Contains("-?") ||
|
|
||||||
appliedCommand.Arguments.Contains("/?"))
|
|
||||||
{
|
|
||||||
// NOTE: this is a temporary stage in refactoring toward the ClicCommandLineParser being used at the CLI entry point.
|
|
||||||
throw new HelpException(parseResult.Command().HelpView());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (parseResult.Errors.Any())
|
if (parseResult.Errors.Any())
|
||||||
{
|
{
|
||||||
|
@ -32,5 +24,18 @@ namespace Microsoft.DotNet.Cli
|
||||||
helpText: parseResult?.Command()?.HelpView());
|
helpText: parseResult?.Command()?.HelpView());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void ShowHelpIfRequested(this ParseResult parseResult)
|
||||||
|
{
|
||||||
|
var appliedCommand = parseResult.AppliedCommand();
|
||||||
|
|
||||||
|
if (appliedCommand.HasOption("help") ||
|
||||||
|
appliedCommand.Arguments.Contains("-?") ||
|
||||||
|
appliedCommand.Arguments.Contains("/?"))
|
||||||
|
{
|
||||||
|
// NOTE: this is a temporary stage in refactoring toward the ClicCommandLineParser being used at the CLI entry point.
|
||||||
|
throw new HelpException(parseResult.Command().HelpView());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
44
test/dotnet.Tests/GivenThatTheUserRequestsHelp.cs
Normal file
44
test/dotnet.Tests/GivenThatTheUserRequestsHelp.cs
Normal file
|
@ -0,0 +1,44 @@
|
||||||
|
// 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.Tools.Test.Utilities;
|
||||||
|
using Xunit;
|
||||||
|
|
||||||
|
namespace dotnet.Tests
|
||||||
|
{
|
||||||
|
public class GivenThatTheUserRequestsHelp
|
||||||
|
{
|
||||||
|
[Theory]
|
||||||
|
[InlineData("-h")]
|
||||||
|
[InlineData("add -h")]
|
||||||
|
[InlineData("add package -h")]
|
||||||
|
[InlineData("add reference -h")]
|
||||||
|
[InlineData("build -h")]
|
||||||
|
[InlineData("cache -h")]
|
||||||
|
[InlineData("clean -h")]
|
||||||
|
[InlineData("list -h")]
|
||||||
|
[InlineData("migrate -h")]
|
||||||
|
[InlineData("msbuild -h")]
|
||||||
|
[InlineData("new -h")]
|
||||||
|
[InlineData("nuget -h")]
|
||||||
|
[InlineData("pack -h")]
|
||||||
|
[InlineData("publish -h")]
|
||||||
|
[InlineData("remove -h")]
|
||||||
|
[InlineData("restore -h")]
|
||||||
|
[InlineData("run -h")]
|
||||||
|
[InlineData("sln -h")]
|
||||||
|
[InlineData("sln add -h")]
|
||||||
|
[InlineData("sln list -h")]
|
||||||
|
[InlineData("sln remove -h")]
|
||||||
|
[InlineData("test -h")]
|
||||||
|
public void TheResponseIsNotAnError(string commandLine)
|
||||||
|
{
|
||||||
|
var result = new DotnetCommand()
|
||||||
|
.ExecuteWithCapturedOutput(commandLine);
|
||||||
|
|
||||||
|
result.ExitCode.Should().Be(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue