Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions eng/Version.Details.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
<Uri>https://github.com/microsoft/clrmd</Uri>
<Sha>d724947392626b66e39b525998a8817447d50380</Sha>
</Dependency>
<Dependency Name="System.Commandline" Version="2.0.0-beta7.25365.101">
<Uri>https://github.com/dotnet/dotnet</Uri>
<Sha>78061f4bcc414fa2054be6237b1fd3813d8edf6b</Sha>
</Dependency>
</ProductDependencies>
<ToolsetDependencies>
<Dependency Name="Microsoft.DotNet.Arcade.Sdk" Version="10.0.0-beta.25351.106">
Expand Down
2 changes: 1 addition & 1 deletion eng/Versions.props
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
<MicrosoftExtensionsLoggingConsoleVersion>6.0.0</MicrosoftExtensionsLoggingConsoleVersion>
<!-- Need version that understands UseAppFilters sentinel. -->
<MicrosoftExtensionsLoggingEventSourceVersion>5.0.1</MicrosoftExtensionsLoggingEventSourceVersion>
<SystemCommandLineVersion>2.0.0-beta5.25210.1</SystemCommandLineVersion>
<SystemCommandLineVersion>2.0.0-beta7.25365.101</SystemCommandLineVersion>
<SystemComponentModelAnnotationsVersion>5.0.0</SystemComponentModelAnnotationsVersion>
<SystemBuffersVersion>4.5.1</SystemBuffersVersion>
<SystemDiagnosticsDiagnosticSourceVersion>8.0.1</SystemDiagnosticsDiagnosticSourceVersion>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,6 @@ private sealed class CommandGroup
{
private Command _rootCommand;
private readonly Dictionary<string, CommandHandler> _commandHandlers = new();
private readonly ParseResult _emptyParseResult;

/// <summary>
/// Create an instance of the command processor;
Expand All @@ -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<string>());
}

/// <summary>
Expand All @@ -300,15 +295,7 @@ public CommandGroup(string commandPrompt = null)
/// <exception cref="DiagnosticsException">parsing error</exception>
internal bool Execute(IReadOnlyList<string> commandLine, IServiceProvider services)
{
IConsoleService consoleService = services.GetService<IConsoleService>();
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)
{
Expand Down Expand Up @@ -433,14 +420,18 @@ internal void CreateCommand(Type type, CommandAttribute commandAttribute, Func<I
// Build or re-build parser instance after this command is added
}

#pragma warning disable IDE0060 // Remove unused parameter
// We are waiting on a way to provide the width in the action or the InvocationConfiguration.
internal string GetDetailedHelp(Command command, IServiceProvider services, int windowWidth)
#pragma warning restore IDE0060 // Remove unused parameter
{
StringWriter console = new();

// Get the command help
HelpBuilder helpBuilder = new(maxWidth: windowWidth);
HelpContext helpContext = new(helpBuilder, command, console, _emptyParseResult);
helpBuilder.Write(helpContext);
// Add a stub help option, invoke it, and remove it. The invocation will
// write the help text to the console writer.
command.Options.Add(new HelpOption() { Hidden = true });
command.Parse(["--help"]).Invoke(new() { Output = console });
command.Options.RemoveAt(command.Options.Count - 1);

// Get the detailed help if any
if (TryGetCommandHandler(command.Name, out CommandHandler handler))
Expand Down
2 changes: 1 addition & 1 deletion src/Tools/Common/Commands/ProcessStatus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class ProcessStatusCommandHandler
public static Command ProcessStatusCommand(string description)
{
Command statusCommand = new(name: "ps", description);
statusCommand.SetAction((parseResult, ct) => Task.FromResult(ProcessStatus(parseResult.Configuration.Output, parseResult.Configuration.Error)));
statusCommand.SetAction((parseResult, ct) => Task.FromResult(ProcessStatus(parseResult.InvocationConfiguration.Output, parseResult.InvocationConfiguration.Error)));
return statusCommand;
}

Expand Down
17 changes: 8 additions & 9 deletions src/Tools/Common/ProcessTerminationHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,14 @@ internal sealed class ProcessTerminationHandler : IDisposable

internal static async Task<int> InvokeAsync(ParseResult parseResult, string blockedSignals = "")
{
using ProcessTerminationHandler terminationHandler = ConfigureTerminationHandler(parseResult, blockedSignals);
return await parseResult.InvokeAsync(terminationHandler.GetToken).ConfigureAwait(false);
}

private static ProcessTerminationHandler ConfigureTerminationHandler(ParseResult parseResult, string blockedSignals)
{
// Use custom process terminate handler for the command line tool parse result.
parseResult.Configuration.ProcessTerminationTimeout = null;
return new ProcessTerminationHandler(blockedSignals);
using ProcessTerminationHandler terminationHandler = new(blockedSignals);
return await parseResult.InvokeAsync(
configuration: new InvocationConfiguration
{
// System.CommandLine should not interfere with Ctrl+C
ProcessTerminationTimeout = null,
},
cancellationToken: terminationHandler.GetToken).ConfigureAwait(false);
}

private ProcessTerminationHandler(string blockedSignals)
Expand Down
4 changes: 2 additions & 2 deletions src/Tools/dotnet-counters/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ private static Command MonitorCommand()

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

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

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

collectCommand.SetAction((parseResult, ct) => new CounterMonitor(parseResult.Configuration.Output, parseResult.Configuration.Error).Collect(
collectCommand.SetAction((parseResult, ct) => new CounterMonitor(parseResult.InvocationConfiguration.Output, parseResult.InvocationConfiguration.Error).Collect(
ct,
counters: parseResult.GetValue(CounterOption),
processId: parseResult.GetValue(ProcessIdOption),
Expand Down
6 changes: 3 additions & 3 deletions src/Tools/dotnet-dump/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ private static Command CollectCommand()
};

command.SetAction((parseResult) => new Dumper().Collect(
stdOutput: parseResult.Configuration.Output,
stdError: parseResult.Configuration.Error,
stdOutput: parseResult.InvocationConfiguration.Output,
stdError: parseResult.InvocationConfiguration.Error,
processId: parseResult.GetValue(ProcessIdOption),
output: parseResult.GetValue(OutputOption),
diag: parseResult.GetValue(DiagnosticLoggingOption),
Expand All @@ -60,7 +60,7 @@ private static Command CollectCommand()
private static readonly Option<string> OutputOption =
new("--output", "-o")
{
Description = @"The path where collected dumps should be written. Defaults to '.\dump_YYYYMMDD_HHMMSS.dmp' on Windows and './core_YYYYMMDD_HHMMSS'
Description = @"The path where collected dumps should be written. Defaults to '.\dump_YYYYMMDD_HHMMSS.dmp' on Windows and './core_YYYYMMDD_HHMMSS'
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."
};

Expand Down
8 changes: 4 additions & 4 deletions src/Tools/dotnet-sos/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ private static Command InstallCommand()
};

installCommand.SetAction(parseResult => Invoke(
parseResult.Configuration.Output,
parseResult.Configuration.Error,
parseResult.InvocationConfiguration.Output,
parseResult.InvocationConfiguration.Error,
architecture: parseResult.GetValue(ArchitectureOption),
install: true));

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

uninstallCommand.SetAction(parseResult => Invoke(
parseResult.Configuration.Output,
parseResult.Configuration.Error,
parseResult.InvocationConfiguration.Output,
parseResult.InvocationConfiguration.Error,
architecture: null,
install: false));

Expand Down
4 changes: 2 additions & 2 deletions src/Tools/dotnet-stack/ReportCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,8 @@ public static Command ReportCommand()
};

reportCommand.SetAction((parseResult, ct) => Report(ct,
stdOutput: parseResult.Configuration.Output,
stdError: parseResult.Configuration.Error,
stdOutput: parseResult.InvocationConfiguration.Output,
stdError: parseResult.InvocationConfiguration.Error,
processId: parseResult.GetValue(ProcessIdOption),
name: parseResult.GetValue(NameOption),
duration: parseResult.GetValue(DurationOption)));
Expand Down
4 changes: 2 additions & 2 deletions src/Tools/dotnet-stack/Symbolicate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -306,8 +306,8 @@ public static Command SymbolicateCommand()
};

symbolicateCommand.SetAction((parseResult, ct) => Task.FromResult(Symbolicate(
stdOutput: parseResult.Configuration.Output,
stdError: parseResult.Configuration.Error,
stdOutput: parseResult.InvocationConfiguration.Output,
stdError: parseResult.InvocationConfiguration.Error,
inputPath: parseResult.GetValue(InputFileArgument),
searchDir: parseResult.GetValue(SearchDirectoryOption),
output: parseResult.GetValue(OutputFileOption),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ public static Command ConvertCommand()
};

convertCommand.SetAction((parseResult, ct) => Task.FromResult(ConvertFile(
stdOut: parseResult.Configuration.Output,
stdError: parseResult.Configuration.Error,
stdOut: parseResult.InvocationConfiguration.Output,
stdError: parseResult.InvocationConfiguration.Error,
inputFilename: parseResult.GetValue(InputFileArgument),
format: parseResult.GetValue(CommonOptions.ConvertFormatOption),
output: parseResult.GetValue(OutputOption
Expand Down
Loading