diff --git a/DevProxy.Abstractions/Proxy/IProxyConfiguration.cs b/DevProxy.Abstractions/Proxy/IProxyConfiguration.cs index a4b08687..4d46bfc1 100644 --- a/DevProxy.Abstractions/Proxy/IProxyConfiguration.cs +++ b/DevProxy.Abstractions/Proxy/IProxyConfiguration.cs @@ -41,6 +41,7 @@ public interface IProxyConfiguration LogLevel LogLevel { get; } ReleaseType NewVersionNotification { get; } bool NoFirstRun { get; set; } + bool NoWatch { get; set; } int Port { get; set; } bool Record { get; set; } bool ShowTimestamps { get; } diff --git a/DevProxy/Commands/DevProxyCommand.cs b/DevProxy/Commands/DevProxyCommand.cs index 249290d8..6ce7ff9f 100644 --- a/DevProxy/Commands/DevProxyCommand.cs +++ b/DevProxy/Commands/DevProxyCommand.cs @@ -33,6 +33,7 @@ sealed class DevProxyCommand : RootCommand Description = "The path to the configuration file" }; internal const string NoFirstRunOptionName = "--no-first-run"; + internal const string NoWatchOptionName = "--no-watch"; internal const string AsSystemProxyOptionName = "--as-system-proxy"; internal const string InstallCertOptionName = "--install-cert"; internal const string UrlsToWatchOptionName = "--urls-to-watch"; @@ -402,6 +403,11 @@ private void ConfigureCommand() Description = "Skip the first run experience" }; + var noWatchOption = new Option(NoWatchOptionName) + { + Description = "Disable automatic restart on configuration file changes" + }; + var discoverOption = new Option(DiscoverOptionName) { Description = "Run Dev Proxy in discovery mode" @@ -529,6 +535,7 @@ private void ConfigureCommand() ipAddressOption, logLevelOption, noFirstRunOption, + noWatchOption, outputOption, portOption, recordOption, @@ -613,6 +620,11 @@ private void ConfigureFromOptions(ParseResult parseResult) { _proxyConfiguration.NoFirstRun = noFirstRun.Value; } + var noWatch = parseResult.GetValueOrDefault(NoWatchOptionName); + if (noWatch is not null) + { + _proxyConfiguration.NoWatch = noWatch.Value; + } var asSystemProxy = parseResult.GetValueOrDefault(AsSystemProxyOptionName); if (asSystemProxy is not null) { diff --git a/DevProxy/Proxy/ConfigFileWatcher.cs b/DevProxy/Proxy/ConfigFileWatcher.cs index b3d71003..261ff4d4 100644 --- a/DevProxy/Proxy/ConfigFileWatcher.cs +++ b/DevProxy/Proxy/ConfigFileWatcher.cs @@ -44,6 +44,12 @@ public static void Reset() public Task StartAsync(CancellationToken cancellationToken) { + if (_proxyConfiguration.NoWatch) + { + _logger.LogDebug("Configuration file watching is disabled"); + return Task.CompletedTask; + } + var configFilePath = _proxyConfiguration.ConfigFile; if (string.IsNullOrEmpty(configFilePath) || !File.Exists(configFilePath)) { diff --git a/DevProxy/Proxy/ProxyConfiguration.cs b/DevProxy/Proxy/ProxyConfiguration.cs index 6f6bc095..a4c5d5fd 100755 --- a/DevProxy/Proxy/ProxyConfiguration.cs +++ b/DevProxy/Proxy/ProxyConfiguration.cs @@ -38,6 +38,7 @@ public string ConfigFile [JsonConverter(typeof(JsonStringEnumConverter))] public LogLevel LogLevel { get; set; } = LogLevel.Information; public bool NoFirstRun { get; set; } + public bool NoWatch { get; set; } [JsonConverter(typeof(JsonStringEnumConverter))] public ReleaseType NewVersionNotification { get; set; } = ReleaseType.Stable; public int Port { get; set; } = 8000;