diff options
Diffstat (limited to 'cli/flags.rs')
-rw-r--r-- | cli/flags.rs | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/cli/flags.rs b/cli/flags.rs index aaff45388..dc0e932ef 100644 --- a/cli/flags.rs +++ b/cli/flags.rs @@ -222,6 +222,9 @@ pub struct Flags { pub log_level: Option<Level>, pub no_check: bool, pub no_remote: bool, + /// If true, a list of Node built-in modules will be injected into + /// the import map. + pub compat: bool, pub prompt: bool, pub reload: bool, pub repl: bool, @@ -1490,6 +1493,7 @@ fn runtime_args<'a, 'b>( .arg(v8_flags_arg()) .arg(seed_arg()) .arg(enable_testing_features_arg()) + .arg(compat_arg()) } fn inspect_args<'a, 'b>(app: App<'a, 'b>) -> App<'a, 'b> { @@ -1619,6 +1623,12 @@ fn seed_arg<'a, 'b>() -> Arg<'a, 'b> { }) } +fn compat_arg<'a, 'b>() -> Arg<'a, 'b> { + Arg::with_name("compat") + .long("compat") + .help("Node compatibility mode. Currently only enables built-in node modules like 'fs'.") +} + fn watch_arg<'a, 'b>() -> Arg<'a, 'b> { Arg::with_name("watch") .long("watch") @@ -2228,6 +2238,7 @@ fn runtime_args_parse( location_arg_parse(flags, matches); v8_flags_arg_parse(flags, matches); seed_arg_parse(flags, matches); + compat_arg_parse(flags, matches); inspect_arg_parse(flags, matches); enable_testing_features_arg_parse(flags, matches); } @@ -2313,6 +2324,12 @@ fn seed_arg_parse(flags: &mut Flags, matches: &ArgMatches) { } } +fn compat_arg_parse(flags: &mut Flags, matches: &ArgMatches) { + if matches.is_present("compat") { + flags.compat = true; + } +} + fn no_check_arg_parse(flags: &mut Flags, matches: &clap::ArgMatches) { if matches.is_present("no-check") { flags.no_check = true; @@ -4431,4 +4448,19 @@ mod tests { .to_string() .contains("Expected protocol \"http\" or \"https\"")); } + + #[test] + fn compat() { + let r = flags_from_vec(svec!["deno", "run", "--compat", "foo.js"]); + assert_eq!( + r.unwrap(), + Flags { + subcommand: DenoSubcommand::Run(RunFlags { + script: "foo.js".to_string(), + }), + compat: true, + ..Flags::default() + } + ); + } } |