summaryrefslogtreecommitdiff
path: root/cli/flags.rs
diff options
context:
space:
mode:
authorBartek IwaƄczuk <biwanczuk@gmail.com>2020-09-11 18:19:49 +0200
committerGitHub <noreply@github.com>2020-09-11 18:19:49 +0200
commita3282aa9ed749f2e80618c6e2f25047d9a2bb2d8 (patch)
tree1755f5a8f65f692c3db72365d58dc669c934f3e0 /cli/flags.rs
parent7ff0c4d8c88027a2157df5e2e6c47ef647a2e614 (diff)
feat(unstable): deno run --watch (#7382)
Co-authored-by: Sebastian Seedorf <mail@sebse.de>
Diffstat (limited to 'cli/flags.rs')
-rw-r--r--cli/flags.rs37
1 files changed, 37 insertions, 0 deletions
diff --git a/cli/flags.rs b/cli/flags.rs
index 443411bc3..18fd3b29e 100644
--- a/cli/flags.rs
+++ b/cli/flags.rs
@@ -123,6 +123,7 @@ pub struct Flags {
pub unstable: bool,
pub v8_flags: Option<Vec<String>>,
pub version: bool,
+ pub watch: bool,
pub write_allowlist: Vec<PathBuf>,
}
@@ -562,6 +563,7 @@ fn run_parse(flags: &mut Flags, matches: &clap::ArgMatches) {
flags.argv.push(v);
}
+ flags.watch = matches.is_present("watch");
flags.subcommand = DenoSubcommand::Run { script };
}
@@ -1157,6 +1159,7 @@ fn run_test_args<'a, 'b>(app: App<'a, 'b>) -> App<'a, 'b> {
fn run_subcommand<'a, 'b>() -> App<'a, 'b> {
run_test_args(SubCommand::with_name("run"))
+ .arg(watch_arg())
.setting(AppSettings::TrailingVarArg)
.arg(script_arg())
.about("Run a program given a filename or url to the module. Use '-' as a filename to read from stdin.")
@@ -1409,6 +1412,17 @@ fn v8_flags_arg_parse(flags: &mut Flags, matches: &ArgMatches) {
}
}
+fn watch_arg<'a, 'b>() -> Arg<'a, 'b> {
+ Arg::with_name("watch")
+ .requires("unstable")
+ .long("watch")
+ .help("Watch for file changes and restart process automatically")
+ .long_help(
+ "Watch for file changes and restart process automatically.
+Only local files from entry point module graph are watched.",
+ )
+}
+
fn no_check_arg<'a, 'b>() -> Arg<'a, 'b> {
Arg::with_name("no-check")
.long("no-check")
@@ -1561,6 +1575,29 @@ mod tests {
}
#[test]
+ fn run_watch() {
+ let r = flags_from_vec_safe(svec![
+ "deno",
+ "run",
+ "--unstable",
+ "--watch",
+ "script.ts"
+ ]);
+ let flags = r.unwrap();
+ assert_eq!(
+ flags,
+ Flags {
+ subcommand: DenoSubcommand::Run {
+ script: "script.ts".to_string(),
+ },
+ watch: true,
+ unstable: true,
+ ..Flags::default()
+ }
+ );
+ }
+
+ #[test]
fn run_reload_allow_write() {
let r = flags_from_vec_safe(svec![
"deno",