Skip to content

Commit dcfbc41

Browse files
committed
Merge more changes from system.commandline
1 parent d7b7bd8 commit dcfbc41

11 files changed

Lines changed: 40 additions & 47 deletions

File tree

eng/Version.Details.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@
99
<Uri>https://github.com/microsoft/clrmd</Uri>
1010
<Sha>d724947392626b66e39b525998a8817447d50380</Sha>
1111
</Dependency>
12+
<Dependency Name="System.Commandline" Version="2.0.0-beta7.25365.101">
13+
<Uri>https://github.com/dotnet/dotnet</Uri>
14+
<Sha>78061f4bcc414fa2054be6237b1fd3813d8edf6b</Sha>
15+
</Dependency>
1216
</ProductDependencies>
1317
<ToolsetDependencies>
1418
<Dependency Name="Microsoft.DotNet.Arcade.Sdk" Version="10.0.0-beta.25351.106">

eng/Versions.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
<MicrosoftExtensionsLoggingConsoleVersion>6.0.0</MicrosoftExtensionsLoggingConsoleVersion>
5757
<!-- Need version that understands UseAppFilters sentinel. -->
5858
<MicrosoftExtensionsLoggingEventSourceVersion>5.0.1</MicrosoftExtensionsLoggingEventSourceVersion>
59-
<SystemCommandLineVersion>2.0.0-beta5.25210.1</SystemCommandLineVersion>
59+
<SystemCommandLineVersion>2.0.0-beta7.25365.101</SystemCommandLineVersion>
6060
<SystemComponentModelAnnotationsVersion>5.0.0</SystemComponentModelAnnotationsVersion>
6161
<SystemBuffersVersion>4.5.1</SystemBuffersVersion>
6262
<SystemDiagnosticsDiagnosticSourceVersion>8.0.1</SystemDiagnosticsDiagnosticSourceVersion>

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

Lines changed: 11 additions & 21 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);
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))

src/Tools/Common/Commands/ProcessStatus.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public class ProcessStatusCommandHandler
2323
public static Command ProcessStatusCommand(string description)
2424
{
2525
Command statusCommand = new(name: "ps", description);
26-
statusCommand.SetAction((parseResult, ct) => Task.FromResult(ProcessStatus(parseResult.Configuration.Output, parseResult.Configuration.Error)));
26+
statusCommand.SetAction((parseResult, ct) => Task.FromResult(ProcessStatus(parseResult.InvocationConfiguration.Output, parseResult.InvocationConfiguration.Error)));
2727
return statusCommand;
2828
}
2929

src/Tools/Common/ProcessTerminationHandler.cs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,14 @@ internal sealed class ProcessTerminationHandler : IDisposable
2424

2525
internal static async Task<int> InvokeAsync(ParseResult parseResult, string blockedSignals = "")
2626
{
27-
using ProcessTerminationHandler terminationHandler = ConfigureTerminationHandler(parseResult, blockedSignals);
28-
return await parseResult.InvokeAsync(terminationHandler.GetToken).ConfigureAwait(false);
29-
}
30-
31-
private static ProcessTerminationHandler ConfigureTerminationHandler(ParseResult parseResult, string blockedSignals)
32-
{
33-
// Use custom process terminate handler for the command line tool parse result.
34-
parseResult.Configuration.ProcessTerminationTimeout = null;
35-
return new ProcessTerminationHandler(blockedSignals);
27+
using ProcessTerminationHandler terminationHandler = new(blockedSignals);
28+
return await parseResult.InvokeAsync(
29+
configuration: new InvocationConfiguration
30+
{
31+
// System.CommandLine should not interfere with Ctrl+C
32+
ProcessTerminationTimeout = null,
33+
},
34+
cancellationToken: terminationHandler.GetToken).ConfigureAwait(false);
3635
}
3736

3837
private ProcessTerminationHandler(string blockedSignals)

src/Tools/dotnet-counters/Program.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ private static Command MonitorCommand()
3838

3939
monitorCommand.TreatUnmatchedTokensAsErrors = false; // see the logic in Main
4040

41-
monitorCommand.SetAction(static (parseResult, ct) => new CounterMonitor(parseResult.Configuration.Output, parseResult.Configuration.Error).Monitor(
41+
monitorCommand.SetAction(static (parseResult, ct) => new CounterMonitor(parseResult.InvocationConfiguration.Output, parseResult.InvocationConfiguration.Error).Monitor(
4242
ct,
4343
counters: parseResult.GetValue(CounterOption),
4444
processId: parseResult.GetValue(ProcessIdOption),
@@ -77,7 +77,7 @@ private static Command CollectCommand()
7777

7878
collectCommand.TreatUnmatchedTokensAsErrors = false; // see the logic in Main
7979

80-
collectCommand.SetAction((parseResult, ct) => new CounterMonitor(parseResult.Configuration.Output, parseResult.Configuration.Error).Collect(
80+
collectCommand.SetAction((parseResult, ct) => new CounterMonitor(parseResult.InvocationConfiguration.Output, parseResult.InvocationConfiguration.Error).Collect(
8181
ct,
8282
counters: parseResult.GetValue(CounterOption),
8383
processId: parseResult.GetValue(ProcessIdOption),

src/Tools/dotnet-dump/Program.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ private static Command CollectCommand()
3232
};
3333

3434
command.SetAction((parseResult) => new Dumper().Collect(
35-
stdOutput: parseResult.Configuration.Output,
36-
stdError: parseResult.Configuration.Error,
35+
stdOutput: parseResult.InvocationConfiguration.Output,
36+
stdError: parseResult.InvocationConfiguration.Error,
3737
processId: parseResult.GetValue(ProcessIdOption),
3838
output: parseResult.GetValue(OutputOption),
3939
diag: parseResult.GetValue(DiagnosticLoggingOption),
@@ -60,7 +60,7 @@ private static Command CollectCommand()
6060
private static readonly Option<string> OutputOption =
6161
new("--output", "-o")
6262
{
63-
Description = @"The path where collected dumps should be written. Defaults to '.\dump_YYYYMMDD_HHMMSS.dmp' on Windows and './core_YYYYMMDD_HHMMSS'
63+
Description = @"The path where collected dumps should be written. Defaults to '.\dump_YYYYMMDD_HHMMSS.dmp' on Windows and './core_YYYYMMDD_HHMMSS'
6464
on Linux where YYYYMMDD is Year/Month/Day and HHMMSS is Hour/Minute/Second. Otherwise, it is the full path and file name of the dump."
6565
};
6666

src/Tools/dotnet-sos/Program.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ private static Command InstallCommand()
3232
};
3333

3434
installCommand.SetAction(parseResult => Invoke(
35-
parseResult.Configuration.Output,
36-
parseResult.Configuration.Error,
35+
parseResult.InvocationConfiguration.Output,
36+
parseResult.InvocationConfiguration.Error,
3737
architecture: parseResult.GetValue(ArchitectureOption),
3838
install: true));
3939

@@ -53,8 +53,8 @@ private static Command UninstallCommand()
5353
description: "Uninstalls SOS and reverts any configuration changes to LLDB.");
5454

5555
uninstallCommand.SetAction(parseResult => Invoke(
56-
parseResult.Configuration.Output,
57-
parseResult.Configuration.Error,
56+
parseResult.InvocationConfiguration.Output,
57+
parseResult.InvocationConfiguration.Error,
5858
architecture: null,
5959
install: false));
6060

src/Tools/dotnet-stack/ReportCommand.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,8 +193,8 @@ public static Command ReportCommand()
193193
};
194194

195195
reportCommand.SetAction((parseResult, ct) => Report(ct,
196-
stdOutput: parseResult.Configuration.Output,
197-
stdError: parseResult.Configuration.Error,
196+
stdOutput: parseResult.InvocationConfiguration.Output,
197+
stdError: parseResult.InvocationConfiguration.Error,
198198
processId: parseResult.GetValue(ProcessIdOption),
199199
name: parseResult.GetValue(NameOption),
200200
duration: parseResult.GetValue(DurationOption)));

src/Tools/dotnet-stack/Symbolicate.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -306,8 +306,8 @@ public static Command SymbolicateCommand()
306306
};
307307

308308
symbolicateCommand.SetAction((parseResult, ct) => Task.FromResult(Symbolicate(
309-
stdOutput: parseResult.Configuration.Output,
310-
stdError: parseResult.Configuration.Error,
309+
stdOutput: parseResult.InvocationConfiguration.Output,
310+
stdError: parseResult.InvocationConfiguration.Error,
311311
inputPath: parseResult.GetValue(InputFileArgument),
312312
searchDir: parseResult.GetValue(SearchDirectoryOption),
313313
output: parseResult.GetValue(OutputFileOption),

0 commit comments

Comments
 (0)