diff --git a/docs/commandline/tye-run.md b/docs/commandline/tye-run.md index 07d46ad4..7112d9ea 100644 --- a/docs/commandline/tye-run.md +++ b/docs/commandline/tye-run.md @@ -47,9 +47,9 @@ If a directory path is specified, `tye run` will default to using these files, i Write distributed traces to the specified providers. Supported providers are zipkin. -- `--debug` +- `--debug ` - Waits for debugger attach in all services. + Waits for debugger attach to service. Specify `*` to wait to attach to all services. ## Examples @@ -68,5 +68,5 @@ If a directory path is specified, `tye run` will default to using these files, i - Run an application and wait for all projects to debug attach: ```text - tye run --debug + tye run --debug * ``` diff --git a/src/Microsoft.Tye.Hosting/ProcessRunner.cs b/src/Microsoft.Tye.Hosting/ProcessRunner.cs index e33613d3..1d759b63 100644 --- a/src/Microsoft.Tye.Hosting/ProcessRunner.cs +++ b/src/Microsoft.Tye.Hosting/ProcessRunner.cs @@ -18,14 +18,12 @@ namespace Microsoft.Tye.Hosting public class ProcessRunner : IApplicationProcessor { private readonly ILogger _logger; - private readonly bool _debugMode; - private readonly bool _buildProjects; + private readonly ProcessRunnerOptions _options; public ProcessRunner(ILogger logger, ProcessRunnerOptions options) { _logger = logger; - _debugMode = options.DebugMode; - _buildProjects = options.BuildProjects; + _options = options; } public Task StartAsync(Tye.Hosting.Model.Application application) @@ -103,7 +101,7 @@ namespace Microsoft.Tye.Hosting if (service.Status.ProjectFilePath != null && service.Description.RunInfo is ProjectRunInfo project2 && project2.Build && - _buildProjects) + _options.BuildProjects) { // Sometimes building can fail because of file locking (like files being open in VS) _logger.LogInformation("Building project {ProjectFile}", service.Status.ProjectFilePath); @@ -146,7 +144,7 @@ namespace Microsoft.Tye.Hosting application.PopulateEnvironment(service, (k, v) => environment[k] = v); - if (_debugMode) + if (_options.DebugMode && (_options.DebugAllServices || _options.ServicesToDebug.Contains(serviceName, StringComparer.OrdinalIgnoreCase))) { environment["DOTNET_STARTUP_HOOKS"] = typeof(Hosting.Runtime.HostingRuntimeHelpers).Assembly.Location; } diff --git a/src/Microsoft.Tye.Hosting/ProcessRunnerOptions.cs b/src/Microsoft.Tye.Hosting/ProcessRunnerOptions.cs index 08e8d3b7..68d763b5 100644 --- a/src/Microsoft.Tye.Hosting/ProcessRunnerOptions.cs +++ b/src/Microsoft.Tye.Hosting/ProcessRunnerOptions.cs @@ -11,13 +11,17 @@ namespace Microsoft.Tye.Hosting { public bool DebugMode { get; set; } public bool BuildProjects { get; set; } + public string[]? ServicesToDebug { get; set; } + public bool DebugAllServices { get; set; } - public static ProcessRunnerOptions FromArgs(string[] args) + public static ProcessRunnerOptions FromArgs(string[] args, string[] servicesToDebug) { return new ProcessRunnerOptions { BuildProjects = !args.Contains("--no-build"), - DebugMode = args.Contains("--debug") + DebugMode = args.Contains("--debug"), + ServicesToDebug = servicesToDebug, + DebugAllServices = servicesToDebug.Contains("*", StringComparer.OrdinalIgnoreCase) }; } } diff --git a/src/Microsoft.Tye.Hosting/TyeHost.cs b/src/Microsoft.Tye.Hosting/TyeHost.cs index cb6cca8f..73ce2e4c 100644 --- a/src/Microsoft.Tye.Hosting/TyeHost.cs +++ b/src/Microsoft.Tye.Hosting/TyeHost.cs @@ -34,11 +34,18 @@ namespace Microsoft.Tye.Hosting private readonly Tye.Hosting.Model.Application _application; private readonly string[] _args; + private readonly string[] _servicesToDebug; public TyeHost(Tye.Hosting.Model.Application application, string[] args) + : this(application, args, new string[0]) + { + } + + public TyeHost(Tye.Hosting.Model.Application application, string[] args, string[] servicesToDebug) { _application = application; _args = args; + _servicesToDebug = servicesToDebug; } public Tye.Hosting.Model.Application Application => _application; @@ -73,7 +80,7 @@ namespace Microsoft.Tye.Hosting var configuration = app.Configuration; - _processor = CreateApplicationProcessor(_args, _logger, configuration); + _processor = CreateApplicationProcessor(_args, _servicesToDebug, _logger, configuration); await app.StartAsync(); @@ -238,7 +245,7 @@ namespace Microsoft.Tye.Hosting return false; } - private static AggregateApplicationProcessor CreateApplicationProcessor(string[] args, Microsoft.Extensions.Logging.ILogger logger, IConfiguration configuration) + private static AggregateApplicationProcessor CreateApplicationProcessor(string[] args, string[] _servicesToDebug, Microsoft.Extensions.Logging.ILogger logger, IConfiguration configuration) { var diagnosticOptions = DiagnosticOptions.FromConfiguration(configuration); var diagnosticsCollector = new DiagnosticsCollector(logger, diagnosticOptions); @@ -251,7 +258,7 @@ namespace Microsoft.Tye.Hosting new EventPipeDiagnosticsRunner(logger, diagnosticsCollector), new ProxyService(logger), new DockerRunner(logger), - new ProcessRunner(logger, ProcessRunnerOptions.FromArgs(args)), + new ProcessRunner(logger, ProcessRunnerOptions.FromArgs(args, _servicesToDebug)), }; // If the docker command is specified then transform the ProjectRunInfo into DockerRunInfo diff --git a/src/tye/Program.RunCommand.cs b/src/tye/Program.RunCommand.cs index 815ab917..9c9d82e1 100644 --- a/src/tye/Program.RunCommand.cs +++ b/src/tye/Program.RunCommand.cs @@ -51,7 +51,8 @@ namespace Microsoft.Tye command.AddOption(new Option("--debug") { - Description = "Wait for debugger attach in all services.", + Argument = new Argument("service"), + Description = "Wait for debugger attach to specific service. Specify \"*\" to wait for all services.", Required = false }); @@ -61,7 +62,7 @@ namespace Microsoft.Tye Required = false }); - command.Handler = CommandHandler.Create(async (console, path) => + command.Handler = CommandHandler.Create(async (console, path, debug) => { // Workaround for https://github.com/dotnet/command-line-api/issues/723#issuecomment-593062654 if (path is null) @@ -74,7 +75,7 @@ namespace Microsoft.Tye InitializeThreadPoolSettings(serviceCount); - using var host = new TyeHost(application.ToHostingApplication(), args); + using var host = new TyeHost(application.ToHostingApplication(), args, debug); await host.RunAsync(); });