Exit on change option

This commit is contained in:
Victor Hurdugaci 2016-01-22 11:42:34 -08:00
parent d20b14d846
commit 3e2798957a
2 changed files with 20 additions and 1 deletions

View File

@ -19,6 +19,8 @@ namespace Microsoft.Dnx.Watcher.Core
private readonly ILogger _logger;
public bool ExitOnChange { get; set; }
public DnxWatcher(
Func<string, IFileWatcher> fileWatcherFactory,
Func<IProcessWatcher> 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;
}
}
}
}

View File

@ -77,10 +77,15 @@ namespace Microsoft.Dnx.Watcher
CommandOptionType.SingleValue);
var workingDirArg = app.Option(
"--workingDir <DIR>",
"--working-dir <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();