Merge pull request #6128 from jonsequitur/fix-subcommand-help-regression

check for help in DotNetTopLevelCommandBase
This commit is contained in:
Livar 2017-03-23 13:11:16 -07:00 committed by GitHub
commit 87527c2e05
3 changed files with 59 additions and 8 deletions

View file

@ -28,6 +28,8 @@ namespace Microsoft.DotNet.Cli
ParseResult = parser.ParseFrom($"dotnet {CommandName}", args);
ParseResult.ShowHelpIfRequested();
var subcommandName = ParseResult.Command().Name;
try

View file

@ -13,6 +13,19 @@ namespace Microsoft.DotNet.Cli
Console.WriteLine(parseResult.Command().HelpView());
public static void ShowHelpOrErrorIfAppropriate(this ParseResult parseResult)
{
parseResult.ShowHelpIfRequested();
if (parseResult.Errors.Any())
{
throw new CommandParsingException(
message: string.Join(Environment.NewLine,
parseResult.Errors.Select(e => e.Message)),
helpText: parseResult?.Command()?.HelpView());
}
}
public static void ShowHelpIfRequested(this ParseResult parseResult)
{
var appliedCommand = parseResult.AppliedCommand();
@ -23,14 +36,6 @@ namespace Microsoft.DotNet.Cli
// 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())
{
throw new CommandParsingException(
message: string.Join(Environment.NewLine,
parseResult.Errors.Select(e => e.Message)),
helpText: parseResult?.Command()?.HelpView());
}
}
}
}

View 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);
}
}
}