File tree Expand file tree Collapse file tree 4 files changed +9
-6
lines changed
Tests/dotnet-add-reference.Tests Expand file tree Collapse file tree 4 files changed +9
-6
lines changed Original file line number Diff line number Diff line change 22// Licensed under the MIT license. See LICENSE file in the project root for full license information.
33
44using System ;
5+ using System . CommandLine . Parsing ;
56
67namespace Microsoft . DotNet . Cli
78{
89 internal class CommandParsingException : Exception
910 {
1011 public CommandParsingException (
1112 string message ,
12- string helpText = null ) : base ( message )
13+ ParseResult parseResult = null ) : base ( message )
1314 {
14- HelpText = helpText ?? "" ;
15+ ParseResult = parseResult ;
1516 Data . Add ( "CLI_User_Displayed_Exception" , true ) ;
1617 }
1718
18- public string HelpText { get ; } = "" ;
19+ public ParseResult ParseResult ;
1920 }
2021}
Original file line number Diff line number Diff line change @@ -26,7 +26,8 @@ public static void ShowHelpOrErrorIfAppropriate(this ParseResult parseResult)
2626 {
2727 throw new CommandParsingException (
2828 message : string . Join ( Environment . NewLine ,
29- parseResult . Errors . Select ( e => e . Message ) ) ) ;
29+ parseResult . Errors . Select ( e => e . Message ) ) ,
30+ parseResult : parseResult ) ;
3031 }
3132 }
3233 else if ( parseResult . HasOption ( "--help" ) )
Original file line number Diff line number Diff line change @@ -70,9 +70,9 @@ public static int Main(string[] args)
7070 : e . Message . Red ( ) . Bold ( ) ) ;
7171
7272 var commandParsingException = e as CommandParsingException ;
73- if ( commandParsingException != null )
73+ if ( commandParsingException != null && commandParsingException . ParseResult != null )
7474 {
75- Reporter . Output . WriteLine ( commandParsingException . HelpText ) ;
75+ commandParsingException . ParseResult . ShowHelp ( ) ;
7676 }
7777
7878 return 1 ;
Original file line number Diff line number Diff line change @@ -127,6 +127,7 @@ public void WhenNoCommandIsPassedItPrintsError(string commandName)
127127 . Execute ( $ "add", commandName ) ;
128128 cmd . Should ( ) . Fail ( ) ;
129129 cmd . StdErr . Should ( ) . Be ( CommonLocalizableStrings . RequiredCommandNotPassed ) ;
130+ cmd . StdOut . Should ( ) . BeVisuallyEquivalentToIfNotLocalized ( AddCommandHelpText ( Directory . GetCurrentDirectory ( ) ) ) ;
130131 }
131132
132133 [ Fact ]
You can’t perform that action at this time.
0 commit comments