Exit on change option
This commit is contained in:
parent
d20b14d846
commit
3e2798957a
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
|
|
|||
Loading…
Reference in New Issue