1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-21 15:04:11 -05:00

feat(flags): support user provided args in repl subcommand (#25605)

closes https://github.com/denoland/deno/issues/11547
This commit is contained in:
Leo Kettmeir 2024-09-13 05:17:46 -07:00 committed by GitHub
parent 394a620da3
commit f2b53d42ac
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -2703,6 +2703,13 @@ fn repl_subcommand() -> Command {
<p(245)>[default: $DENO_DIR/deno_history.txt]</>")) <p(245)>[default: $DENO_DIR/deno_history.txt]</>"))
) )
.arg(env_file_arg()) .arg(env_file_arg())
.arg(
Arg::new("args")
.num_args(0..)
.action(ArgAction::Append)
.value_name("ARGS")
.last(true)
)
} }
fn run_args(command: Command, top_level: bool) -> Command { fn run_args(command: Command, top_level: bool) -> Command {
@ -4711,6 +4718,10 @@ fn repl_parse(
}) })
.transpose()?; .transpose()?;
if let Some(args) = matches.remove_many::<String>("args") {
flags.argv.extend(args);
}
handle_repl_flags( handle_repl_flags(
flags, flags,
ReplFlags { ReplFlags {
@ -10721,6 +10732,25 @@ mod tests {
); );
} }
#[test]
fn repl_user_args() {
let r = flags_from_vec(svec!["deno", "repl", "foo"]);
assert!(r.is_err());
let r = flags_from_vec(svec!["deno", "repl", "--", "foo"]);
assert_eq!(
r.unwrap(),
Flags {
subcommand: DenoSubcommand::Repl(ReplFlags {
eval_files: None,
eval: None,
is_default_command: false,
}),
argv: svec!["foo"],
..Flags::default()
}
);
}
#[test] #[test]
fn bare_with_flag_no_file() { fn bare_with_flag_no_file() {
let r = flags_from_vec(svec!["deno", "--no-config"]); let r = flags_from_vec(svec!["deno", "--no-config"]);