diff options
Diffstat (limited to 'cli/args/flags.rs')
-rw-r--r-- | cli/args/flags.rs | 65 |
1 files changed, 59 insertions, 6 deletions
diff --git a/cli/args/flags.rs b/cli/args/flags.rs index 1743d58c6..5f58911c2 100644 --- a/cli/args/flags.rs +++ b/cli/args/flags.rs @@ -498,6 +498,7 @@ pub struct Flags { pub argv: Vec<String>, pub subcommand: DenoSubcommand, + pub frozen_lockfile: bool, pub ca_stores: Option<Vec<String>>, pub ca_data: Option<CaData>, pub cache_blocklist: Vec<String>, @@ -1487,12 +1488,15 @@ Future runs of this module will trigger no downloads or compilation unless --reload is specified.", ) .defer(|cmd| { - compile_args(cmd).arg(check_arg(false)).arg( - Arg::new("file") - .num_args(1..) - .required(true) - .value_hint(ValueHint::FilePath), - ) + compile_args(cmd) + .arg(check_arg(false)) + .arg( + Arg::new("file") + .num_args(1..) + .required(true) + .value_hint(ValueHint::FilePath), + ) + .arg(frozen_lockfile_arg()) }) } @@ -3271,6 +3275,7 @@ fn runtime_args( app }; app + .arg(frozen_lockfile_arg()) .arg(cached_only_arg()) .arg(location_arg()) .arg(v8_flags_arg()) @@ -3384,6 +3389,17 @@ fn cached_only_arg() -> Arg { .help("Require that remote dependencies are already cached") } +fn frozen_lockfile_arg() -> Arg { + Arg::new("frozen") + .long("frozen") + .alias("frozen-lockfile") + .value_parser(value_parser!(bool)) + .num_args(0..=1) + .require_equals(true) + .default_missing_value("true") + .help("Error out if lockfile is out of date") +} + /// Used for subcommands that operate on executable scripts only. /// `deno fmt` has its own `--ext` arg because its possible values differ. /// If --ext is not provided and the script doesn't have a file extension, @@ -3774,6 +3790,7 @@ fn bundle_parse(flags: &mut Flags, matches: &mut ArgMatches) { fn cache_parse(flags: &mut Flags, matches: &mut ArgMatches) { compile_args_parse(flags, matches); + frozen_lockfile_arg_parse(flags, matches); let files = matches.remove_many::<String>("file").unwrap().collect(); flags.subcommand = DenoSubcommand::Cache(CacheFlags { files }); } @@ -4576,6 +4593,7 @@ fn runtime_args_parse( ) { compile_args_parse(flags, matches); cached_only_arg_parse(flags, matches); + frozen_lockfile_arg_parse(flags, matches); if include_perms { permission_args_parse(flags, matches); } @@ -4667,6 +4685,12 @@ fn cached_only_arg_parse(flags: &mut Flags, matches: &mut ArgMatches) { } } +fn frozen_lockfile_arg_parse(flags: &mut Flags, matches: &mut ArgMatches) { + if let Some(&v) = matches.get_one::<bool>("frozen") { + flags.frozen_lockfile = v; + } +} + fn ext_arg_parse(flags: &mut Flags, matches: &mut ArgMatches) { flags.ext = matches.remove_one::<String>("ext"); } @@ -9845,4 +9869,33 @@ mod tests { } ); } + + #[test] + fn run_with_frozen_lockfile() { + let cases = [ + (Some("--frozen"), true), + (Some("--frozen=true"), true), + (Some("--frozen=false"), false), + (None, false), + ]; + for (flag, frozen) in cases { + let mut args = svec!["deno", "run"]; + if let Some(f) = flag { + args.push(f.into()); + } + args.push("script.ts".into()); + let r = flags_from_vec(args); + assert_eq!( + r.unwrap(), + Flags { + subcommand: DenoSubcommand::Run(RunFlags::new_default( + "script.ts".to_string(), + )), + frozen_lockfile: frozen, + code_cache_enabled: true, + ..Flags::default() + } + ); + } + } } |