From 3e2798957a713a37e24b95344f07f75a86d65689 Mon Sep 17 00:00:00 2001 From: Victor Hurdugaci Date: Fri, 22 Jan 2016 11:42:34 -0800 Subject: [PATCH] Exit on change option --- src/Microsoft.Dnx.Watcher.Core/DnxWatcher.cs | 12 ++++++++++++ src/Microsoft.Dnx.Watcher/Program.cs | 9 ++++++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/Microsoft.Dnx.Watcher.Core/DnxWatcher.cs b/src/Microsoft.Dnx.Watcher.Core/DnxWatcher.cs index e8f03f8e6b..b4a27a9afb 100644 --- a/src/Microsoft.Dnx.Watcher.Core/DnxWatcher.cs +++ b/src/Microsoft.Dnx.Watcher.Core/DnxWatcher.cs @@ -19,6 +19,8 @@ namespace Microsoft.Dnx.Watcher.Core private readonly ILogger _logger; + public bool ExitOnChange { get; set; } + public DnxWatcher( Func fileWatcherFactory, Func processWatcherFactory, @@ -88,6 +90,11 @@ namespace Microsoft.Dnx.Watcher.Core _logger.LogError($"dnx exit code: {dnxExitCode}"); } + if (ExitOnChange) + { + break; + } + _logger.LogInformation("Waiting for a file to change before restarting dnx..."); // Now wait for a file to change before restarting dnx await WaitForProjectFileToChangeAsync(project, cancellationToken); @@ -97,6 +104,11 @@ namespace Microsoft.Dnx.Watcher.Core // This is a file watcher task string changedFile = fileWatchingTask.Result; _logger.LogInformation($"File changed: {fileWatchingTask.Result}"); + + if (ExitOnChange) + { + break; + } } } } diff --git a/src/Microsoft.Dnx.Watcher/Program.cs b/src/Microsoft.Dnx.Watcher/Program.cs index e9e8d720ca..f2b2d9c104 100644 --- a/src/Microsoft.Dnx.Watcher/Program.cs +++ b/src/Microsoft.Dnx.Watcher/Program.cs @@ -77,10 +77,15 @@ namespace Microsoft.Dnx.Watcher CommandOptionType.SingleValue); var workingDirArg = app.Option( - "--workingDir ", + "--working-dir ", "The working directory for DNX. Defaults to the current directory.", CommandOptionType.SingleValue); + var exitOnChangeArg = app.Option( + "--exit-on-change", + "The watcher will exit when a file change is detected instead of restarting the process.", + CommandOptionType.NoValue); + // This option is here just to be displayed in help // it will not be parsed because it is removed before the code is executed app.Option( @@ -104,6 +109,8 @@ namespace Microsoft.Dnx.Watcher Directory.GetCurrentDirectory(); var watcher = DnxWatcher.CreateDefault(_loggerFactory); + watcher.ExitOnChange = exitOnChangeArg.HasValue(); + try { watcher.WatchAsync(projectToRun, dnxArgs, workingDir, cancellationToken).Wait();