@@ -199,7 +199,7 @@ public string GetDetailedHelp(string commandName, IServiceProvider services, int
199199 {
200200 if ( handler . IsCommandSupported ( group . Parser , services ) )
201201 {
202- return group . GetDetailedHelp ( command , services ) ;
202+ return group . GetDetailedHelp ( command , services , consoleWidth ) ;
203203 }
204204 if ( handler . FilterInvokeMessage != null )
205205 {
@@ -295,15 +295,7 @@ public CommandGroup(string commandPrompt = null)
295295 /// <exception cref="DiagnosticsException">parsing error</exception>
296296 internal bool Execute ( IReadOnlyList < string > commandLine , IServiceProvider services )
297297 {
298- IConsoleService consoleService = services . GetService < IConsoleService > ( ) ;
299- CommandLineConfiguration configuration = new ( _rootCommand )
300- {
301- Output = new ConsoleServiceWrapper ( consoleService . Write ) ,
302- Error = new ConsoleServiceWrapper ( consoleService . WriteError )
303- } ;
304-
305- // Parse the command line and invoke the command
306- ParseResult parseResult = configuration . Parse ( commandLine ) ;
298+ ParseResult parseResult = _rootCommand . Parse ( commandLine ) ;
307299
308300 if ( parseResult . Errors . Count > 0 )
309301 {
@@ -312,7 +304,7 @@ internal bool Execute(IReadOnlyList<string> commandLine, IServiceProvider servic
312304 {
313305 sb . AppendLine ( error . Message ) ;
314306 }
315- string helpText = GetDetailedHelp ( parseResult . CommandResult . Command , services ) ;
307+ string helpText = GetDetailedHelp ( parseResult . CommandResult . Command , services , int . MaxValue ) ;
316308 throw new CommandParsingException ( sb . ToString ( ) , helpText ) ;
317309 }
318310 else
@@ -428,20 +420,18 @@ internal void CreateCommand(Type type, CommandAttribute commandAttribute, Func<I
428420 // Build or re-build parser instance after this command is added
429421 }
430422
431- internal string GetDetailedHelp ( Command command , IServiceProvider services )
423+ #pragma warning disable IDE0060 // Remove unused parameter
424+ // We are waiting on a way to provide the width in the action or the InvocationConfiguration.
425+ internal string GetDetailedHelp ( Command command , IServiceProvider services , int windowWidth )
426+ #pragma warning restore IDE0060 // Remove unused parameter
432427 {
433428 StringWriter console = new ( ) ;
434- CommandLineConfiguration configuration = new ( command )
435- {
436- Output = console
437- } ;
438429
439- // Get the command help by parsing the --help option.
440- // The option is hidden so it doesn't show up in the help text .
430+ // Add a stub help option, invoke it, and remove it. The invocation will
431+ // write the help text to the console writer .
441432 command . Options . Add ( new HelpOption ( ) { Hidden = true } ) ;
442- // Invoking the help action writes to configuration.Output.
443- command . Parse ( [ "--help" ] , configuration ) . Invoke ( ) ;
444- command . Options . RemoveAt ( command . Options . Count - 1 ) ; // Remove the help option
433+ command . Parse ( [ "--help" ] ) . Invoke ( new ( ) { Output = console } ) ;
434+ command . Options . RemoveAt ( command . Options . Count - 1 ) ;
445435
446436 // Get the detailed help if any
447437 if ( TryGetCommandHandler ( command . Name , out CommandHandler handler ) )
0 commit comments