From 4a663430f87e1aa40589f4befcf3c42b8b02b7e3 Mon Sep 17 00:00:00 2001 From: Adam Sitnik Date: Wed, 28 May 2025 13:41:16 +0200 Subject: [PATCH 1/3] stop using System.CommandLine types that won't be public anymore --- .../CommandService.cs | 22 +++++++++---------- 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/src/Microsoft.Diagnostics.DebugServices.Implementation/CommandService.cs b/src/Microsoft.Diagnostics.DebugServices.Implementation/CommandService.cs index 89b9a609bd..b04c4e0c1e 100644 --- a/src/Microsoft.Diagnostics.DebugServices.Implementation/CommandService.cs +++ b/src/Microsoft.Diagnostics.DebugServices.Implementation/CommandService.cs @@ -199,7 +199,7 @@ public string GetDetailedHelp(string commandName, IServiceProvider services, int { if (handler.IsCommandSupported(group.Parser, services)) { - return group.GetDetailedHelp(command, services, consoleWidth); + return group.GetDetailedHelp(command, services); } if (handler.FilterInvokeMessage != null) { @@ -276,7 +276,6 @@ private sealed class CommandGroup { private Command _rootCommand; private readonly Dictionary _commandHandlers = new(); - private readonly ParseResult _emptyParseResult; /// /// Create an instance of the command processor; @@ -285,10 +284,6 @@ private sealed class CommandGroup public CommandGroup(string commandPrompt = null) { _rootCommand = new Command(commandPrompt); - - // The actual ParseResult.Empty() has a bug in it where it tries to get the executable name - // and nothing is returned under lldb on Linux causing an index out of range exception. - _emptyParseResult = _rootCommand.Parse(Array.Empty()); } /// @@ -317,7 +312,7 @@ internal bool Execute(IReadOnlyList commandLine, IServiceProvider servic { sb.AppendLine(error.Message); } - string helpText = GetDetailedHelp(parseResult.CommandResult.Command, services, int.MaxValue); + string helpText = GetDetailedHelp(parseResult.CommandResult.Command, services); throw new CommandParsingException(sb.ToString(), helpText); } else @@ -433,14 +428,17 @@ internal void CreateCommand(Type type, CommandAttribute commandAttribute, Func Date: Wed, 28 May 2025 15:06:24 +0200 Subject: [PATCH 2/3] fix some of the failing tests --- .../CommandService.cs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/Microsoft.Diagnostics.DebugServices.Implementation/CommandService.cs b/src/Microsoft.Diagnostics.DebugServices.Implementation/CommandService.cs index b04c4e0c1e..5b953a1c73 100644 --- a/src/Microsoft.Diagnostics.DebugServices.Implementation/CommandService.cs +++ b/src/Microsoft.Diagnostics.DebugServices.Implementation/CommandService.cs @@ -436,9 +436,12 @@ internal string GetDetailedHelp(Command command, IServiceProvider services) Output = console }; - // Get the command help by parsing the --help option - // and invoking the help action that writes to configuration.Output. + // Get the command help by parsing the --help option. + // The option is hidden so it doesn't show up in the help text. + command.Options.Add(new HelpOption() { Hidden = true }); + // Invoking the help action writes to configuration.Output. command.Parse(["--help"], configuration).Invoke(); + command.Options.RemoveAt(command.Options.Count - 1); // Remove the help option // Get the detailed help if any if (TryGetCommandHandler(command.Name, out CommandHandler handler)) From dcfbc418b35ed817a7376d8a3f9e5f4b7db54722 Mon Sep 17 00:00:00 2001 From: Juan Sebastian Hoyos Ayala Date: Mon, 21 Jul 2025 18:12:51 -0700 Subject: [PATCH 3/3] Merge more changes from system.commandline --- eng/Version.Details.xml | 4 +++ eng/Versions.props | 2 +- .../CommandService.cs | 32 +++++++------------ src/Tools/Common/Commands/ProcessStatus.cs | 2 +- src/Tools/Common/ProcessTerminationHandler.cs | 17 +++++----- src/Tools/dotnet-counters/Program.cs | 4 +-- src/Tools/dotnet-dump/Program.cs | 6 ++-- src/Tools/dotnet-sos/Program.cs | 8 ++--- src/Tools/dotnet-stack/ReportCommand.cs | 4 +-- src/Tools/dotnet-stack/Symbolicate.cs | 4 +-- .../CommandLine/Commands/ConvertCommand.cs | 4 +-- 11 files changed, 40 insertions(+), 47 deletions(-) diff --git a/eng/Version.Details.xml b/eng/Version.Details.xml index 260c35a22a..37aac9a99f 100644 --- a/eng/Version.Details.xml +++ b/eng/Version.Details.xml @@ -9,6 +9,10 @@ https://github.com/microsoft/clrmd d724947392626b66e39b525998a8817447d50380 + + https://github.com/dotnet/dotnet + 78061f4bcc414fa2054be6237b1fd3813d8edf6b + diff --git a/eng/Versions.props b/eng/Versions.props index 8e96ea5ed8..fd71110c9a 100644 --- a/eng/Versions.props +++ b/eng/Versions.props @@ -56,7 +56,7 @@ 6.0.0 5.0.1 - 2.0.0-beta5.25210.1 + 2.0.0-beta7.25365.101 5.0.0 4.5.1 8.0.1 diff --git a/src/Microsoft.Diagnostics.DebugServices.Implementation/CommandService.cs b/src/Microsoft.Diagnostics.DebugServices.Implementation/CommandService.cs index 5b953a1c73..14251ece7c 100644 --- a/src/Microsoft.Diagnostics.DebugServices.Implementation/CommandService.cs +++ b/src/Microsoft.Diagnostics.DebugServices.Implementation/CommandService.cs @@ -199,7 +199,7 @@ public string GetDetailedHelp(string commandName, IServiceProvider services, int { if (handler.IsCommandSupported(group.Parser, services)) { - return group.GetDetailedHelp(command, services); + return group.GetDetailedHelp(command, services, consoleWidth); } if (handler.FilterInvokeMessage != null) { @@ -295,15 +295,7 @@ public CommandGroup(string commandPrompt = null) /// parsing error internal bool Execute(IReadOnlyList commandLine, IServiceProvider services) { - IConsoleService consoleService = services.GetService(); - CommandLineConfiguration configuration = new(_rootCommand) - { - Output = new ConsoleServiceWrapper(consoleService.Write), - Error = new ConsoleServiceWrapper(consoleService.WriteError) - }; - - // Parse the command line and invoke the command - ParseResult parseResult = configuration.Parse(commandLine); + ParseResult parseResult = _rootCommand.Parse(commandLine); if (parseResult.Errors.Count > 0) { @@ -312,7 +304,7 @@ internal bool Execute(IReadOnlyList commandLine, IServiceProvider servic { sb.AppendLine(error.Message); } - string helpText = GetDetailedHelp(parseResult.CommandResult.Command, services); + string helpText = GetDetailedHelp(parseResult.CommandResult.Command, services, int.MaxValue); throw new CommandParsingException(sb.ToString(), helpText); } else @@ -428,20 +420,18 @@ internal void CreateCommand(Type type, CommandAttribute commandAttribute, Func