Skip to content

Commit 53c7036

Browse files
committed
stop using System.CommandLine types that won't be public anymore
1 parent 8bbc63d commit 53c7036

File tree

1 file changed

+10
-12
lines changed

1 file changed

+10
-12
lines changed

src/Microsoft.Diagnostics.DebugServices.Implementation/CommandService.cs

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -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, consoleWidth);
202+
return group.GetDetailedHelp(command, services);
203203
}
204204
if (handler.FilterInvokeMessage != null)
205205
{
@@ -276,7 +276,6 @@ private sealed class CommandGroup
276276
{
277277
private Command _rootCommand;
278278
private readonly Dictionary<string, CommandHandler> _commandHandlers = new();
279-
private readonly ParseResult _emptyParseResult;
280279

281280
/// <summary>
282281
/// Create an instance of the command processor;
@@ -285,10 +284,6 @@ private sealed class CommandGroup
285284
public CommandGroup(string commandPrompt = null)
286285
{
287286
_rootCommand = new Command(commandPrompt);
288-
289-
// The actual ParseResult.Empty() has a bug in it where it tries to get the executable name
290-
// and nothing is returned under lldb on Linux causing an index out of range exception.
291-
_emptyParseResult = _rootCommand.Parse(Array.Empty<string>());
292287
}
293288

294289
/// <summary>
@@ -317,7 +312,7 @@ internal bool Execute(IReadOnlyList<string> commandLine, IServiceProvider servic
317312
{
318313
sb.AppendLine(error.Message);
319314
}
320-
string helpText = GetDetailedHelp(parseResult.CommandResult.Command, services, int.MaxValue);
315+
string helpText = GetDetailedHelp(parseResult.CommandResult.Command, services);
321316
throw new CommandParsingException(sb.ToString(), helpText);
322317
}
323318
else
@@ -433,14 +428,17 @@ internal void CreateCommand(Type type, CommandAttribute commandAttribute, Func<I
433428
// Build or re-build parser instance after this command is added
434429
}
435430

436-
internal string GetDetailedHelp(Command command, IServiceProvider services, int windowWidth)
431+
internal string GetDetailedHelp(Command command, IServiceProvider services)
437432
{
438433
StringWriter console = new();
434+
CommandLineConfiguration configuration = new(command)
435+
{
436+
Output = console
437+
};
439438

440-
// Get the command help
441-
HelpBuilder helpBuilder = new(maxWidth: windowWidth);
442-
HelpContext helpContext = new(helpBuilder, command, console, _emptyParseResult);
443-
helpBuilder.Write(helpContext);
439+
// Get the command help by parsing the --help option
440+
// and invoking the help action that writes to configuration.Output.
441+
command.Parse(["--help"], configuration).Invoke();
444442

445443
// Get the detailed help if any
446444
if (TryGetCommandHandler(command.Name, out CommandHandler handler))

0 commit comments

Comments
 (0)