include HelpText in CommandParsingError, write it to stdout
This commit is contained in:
parent
22fb17422f
commit
35732fc07d
4 changed files with 20 additions and 7 deletions
|
@ -10,8 +10,11 @@ namespace Microsoft.DotNet.Cli.CommandLine
|
||||||
{
|
{
|
||||||
private readonly bool _isRequireSubCommandMissing;
|
private readonly bool _isRequireSubCommandMissing;
|
||||||
|
|
||||||
public CommandParsingException(string message) : base(message)
|
public CommandParsingException(
|
||||||
|
string message,
|
||||||
|
string helpText = null) : base(message)
|
||||||
{
|
{
|
||||||
|
HelpText = helpText ?? "";
|
||||||
Data.Add("CLI_User_Displayed_Exception", true);
|
Data.Add("CLI_User_Displayed_Exception", true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -27,6 +30,8 @@ namespace Microsoft.DotNet.Cli.CommandLine
|
||||||
|
|
||||||
public CommandLineApplication Command { get; }
|
public CommandLineApplication Command { get; }
|
||||||
|
|
||||||
|
public string HelpText { get; } = "";
|
||||||
|
|
||||||
public override string Message
|
public override string Message
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
|
|
|
@ -27,8 +27,9 @@ namespace Microsoft.DotNet.Cli
|
||||||
if (parseResult.Errors.Any())
|
if (parseResult.Errors.Any())
|
||||||
{
|
{
|
||||||
throw new CommandParsingException(
|
throw new CommandParsingException(
|
||||||
string.Join(Environment.NewLine,
|
message: string.Join(Environment.NewLine,
|
||||||
parseResult.Errors.Select(e => e.Message)));
|
parseResult.Errors.Select(e => e.Message)),
|
||||||
|
helpText: parseResult?.Command()?.HelpView());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,7 @@ using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
using Microsoft.DotNet.Cli.CommandLine;
|
||||||
using Microsoft.DotNet.Cli.Utils;
|
using Microsoft.DotNet.Cli.Utils;
|
||||||
using Microsoft.DotNet.Configurer;
|
using Microsoft.DotNet.Configurer;
|
||||||
using Microsoft.DotNet.PlatformAbstractions;
|
using Microsoft.DotNet.PlatformAbstractions;
|
||||||
|
@ -84,9 +85,15 @@ namespace Microsoft.DotNet.Cli
|
||||||
}
|
}
|
||||||
catch (Exception e) when (e.ShouldBeDisplayedAsError())
|
catch (Exception e) when (e.ShouldBeDisplayedAsError())
|
||||||
{
|
{
|
||||||
Reporter.Error.WriteLine(CommandContext.IsVerbose() ?
|
Reporter.Error.WriteLine(CommandContext.IsVerbose()
|
||||||
e.ToString().Red().Bold() :
|
? e.ToString().Red().Bold()
|
||||||
e.Message.Red().Bold());
|
: e.Message.Red().Bold());
|
||||||
|
|
||||||
|
var commandParsingException = e as CommandParsingException;
|
||||||
|
if (commandParsingException != null)
|
||||||
|
{
|
||||||
|
Reporter.Output.WriteLine(commandParsingException.HelpText);
|
||||||
|
}
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,7 +20,7 @@ namespace Microsoft.DotNet.Cli
|
||||||
CommonOptions.HelpOption(),
|
CommonOptions.HelpOption(),
|
||||||
Create.Command("add",
|
Create.Command("add",
|
||||||
".NET Add project(s) to a solution file Command",
|
".NET Add project(s) to a solution file Command",
|
||||||
Accept.OneOrMoreArguments()
|
Accept.OneOrMoreArguments(o => CommonLocalizableStrings.SpecifyAtLeastOneProjectToAdd)
|
||||||
.With(name: "args",
|
.With(name: "args",
|
||||||
description: LocalizableStrings.AddSubcommandHelpText),
|
description: LocalizableStrings.AddSubcommandHelpText),
|
||||||
CommonOptions.HelpOption()),
|
CommonOptions.HelpOption()),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue