diff options
author | Nayeem Rahman <muhammed.9939@gmail.com> | 2019-12-03 22:48:53 +0000 |
---|---|---|
committer | Ry Dahl <ry@tinyclouds.org> | 2019-12-03 17:48:53 -0500 |
commit | 91da410fc3bfde76c3c8930c6f8bfd4d5f9b974e (patch) | |
tree | 30e8345ddba04915fc9417d0855a0ca08feb41ac /cli/flags.rs | |
parent | ee013102ff4ce75c1068b6e771ed120fc32a849d (diff) |
feat: Add --no-remote, rename --no-fetch to --cached-only (#3417)
Diffstat (limited to 'cli/flags.rs')
-rw-r--r-- | cli/flags.rs | 49 |
1 files changed, 40 insertions, 9 deletions
diff --git a/cli/flags.rs b/cli/flags.rs index 7d065dd39..f23879e0f 100644 --- a/cli/flags.rs +++ b/cli/flags.rs @@ -84,7 +84,8 @@ pub struct DenoFlags { pub allow_run: bool, pub allow_hrtime: bool, pub no_prompts: bool, - pub no_fetch: bool, + pub no_remote: bool, + pub cached_only: bool, pub seed: Option<u64>, pub v8_flags: Option<Vec<String>>, // Use tokio::runtime::current_thread @@ -400,6 +401,7 @@ fn fetch_parse(flags: &mut DenoFlags, matches: &clap::ArgMatches) { lock_args_parse(flags, matches); importmap_arg_parse(flags, matches); config_arg_parse(flags, matches); + no_remote_arg_parse(flags, matches); if let Some(file) = matches.value_of("file") { flags.argv.push(file.into()); } @@ -422,6 +424,7 @@ fn run_test_args_parse(flags: &mut DenoFlags, matches: &clap::ArgMatches) { importmap_arg_parse(flags, matches); config_arg_parse(flags, matches); v8_flags_arg_parse(flags, matches); + no_remote_arg_parse(flags, matches); if matches.is_present("allow-read") { if matches.value_of("allow-read").is_some() { @@ -474,8 +477,8 @@ fn run_test_args_parse(flags: &mut DenoFlags, matches: &clap::ArgMatches) { flags.allow_write = true; flags.allow_hrtime = true; } - if matches.is_present("no-fetch") { - flags.no_fetch = true; + if matches.is_present("cached-only") { + flags.cached_only = true; } if matches.is_present("current-thread") { @@ -873,6 +876,7 @@ fn fetch_subcommand<'a, 'b>() -> App<'a, 'b> { .arg(lock_write_arg()) .arg(importmap_arg()) .arg(config_arg()) + .arg(no_remote_arg()) .arg(Arg::with_name("file").takes_value(true).required(true)) .about("Fetch the dependencies") .long_about( @@ -899,6 +903,7 @@ fn run_test_args<'a, 'b>(app: App<'a, 'b>) -> App<'a, 'b> { .arg(config_arg()) .arg(lock_arg()) .arg(lock_write_arg()) + .arg(no_remote_arg()) .arg(v8_flags_arg()) .arg( Arg::with_name("allow-read") @@ -949,9 +954,9 @@ fn run_test_args<'a, 'b>(app: App<'a, 'b>) -> App<'a, 'b> { .help("Allow all permissions"), ) .arg( - Arg::with_name("no-fetch") - .long("no-fetch") - .help("Do not download remote modules"), + Arg::with_name("cached-only") + .long("cached-only") + .help("Require that remote dependencies are already cached"), ) .arg( Arg::with_name("current-thread") @@ -1150,6 +1155,18 @@ fn v8_flags_arg_parse(flags: &mut DenoFlags, matches: &ArgMatches) { } } +fn no_remote_arg<'a, 'b>() -> Arg<'a, 'b> { + Arg::with_name("no-remote") + .long("no-remote") + .help("Do not resolve remote modules") +} + +fn no_remote_arg_parse(flags: &mut DenoFlags, matches: &clap::ArgMatches) { + if matches.is_present("no-remote") { + flags.no_remote = true; + } +} + // TODO(ry) move this to utility module and add test. /// Strips fragment part of URL. Panics on bad URL. pub fn resolve_urls(urls: Vec<String>) -> Vec<String> { @@ -2063,14 +2080,28 @@ mod tests { */ #[test] - fn no_fetch() { - let r = flags_from_vec_safe(svec!["deno", "--no-fetch", "script.ts"]); + fn no_remote() { + let r = flags_from_vec_safe(svec!["deno", "--no-remote", "script.ts"]); + assert_eq!( + r.unwrap(), + DenoFlags { + subcommand: DenoSubcommand::Run, + argv: svec!["deno", "script.ts"], + no_remote: true, + ..DenoFlags::default() + } + ); + } + + #[test] + fn cached_only() { + let r = flags_from_vec_safe(svec!["deno", "--cached-only", "script.ts"]); assert_eq!( r.unwrap(), DenoFlags { subcommand: DenoSubcommand::Run, argv: svec!["deno", "script.ts"], - no_fetch: true, + cached_only: true, ..DenoFlags::default() } ); |