mirror of
https://github.com/denoland/deno.git
synced 2024-11-22 15:06:54 -05:00
fix: deno task
forward double hyphen (#14419)
This commit is contained in:
parent
ba799b6729
commit
3b40be2f6e
2 changed files with 46 additions and 19 deletions
62
cli/flags.rs
62
cli/flags.rs
|
@ -512,14 +512,10 @@ To evaluate code in the shell:
|
||||||
";
|
";
|
||||||
|
|
||||||
/// Main entry point for parsing deno's command line flags.
|
/// Main entry point for parsing deno's command line flags.
|
||||||
pub fn flags_from_vec<I, T>(args: I) -> clap::Result<Flags>
|
pub fn flags_from_vec(args: Vec<String>) -> clap::Result<Flags> {
|
||||||
where
|
|
||||||
I: IntoIterator<Item = T>,
|
|
||||||
T: Into<std::ffi::OsString> + Clone,
|
|
||||||
{
|
|
||||||
let version = crate::version::deno();
|
let version = crate::version::deno();
|
||||||
let app = clap_root(&version);
|
let app = clap_root(&version);
|
||||||
let matches = app.clone().try_get_matches_from(args)?;
|
let matches = app.clone().try_get_matches_from(&args)?;
|
||||||
|
|
||||||
let mut flags = Flags::default();
|
let mut flags = Flags::default();
|
||||||
|
|
||||||
|
@ -554,7 +550,7 @@ where
|
||||||
Some(("lsp", m)) => lsp_parse(&mut flags, m),
|
Some(("lsp", m)) => lsp_parse(&mut flags, m),
|
||||||
Some(("repl", m)) => repl_parse(&mut flags, m),
|
Some(("repl", m)) => repl_parse(&mut flags, m),
|
||||||
Some(("run", m)) => run_parse(&mut flags, m),
|
Some(("run", m)) => run_parse(&mut flags, m),
|
||||||
Some(("task", m)) => task_parse(&mut flags, m),
|
Some(("task", m)) => task_parse(&mut flags, m, &args),
|
||||||
Some(("test", m)) => test_parse(&mut flags, m),
|
Some(("test", m)) => test_parse(&mut flags, m),
|
||||||
Some(("types", m)) => types_parse(&mut flags, m),
|
Some(("types", m)) => types_parse(&mut flags, m),
|
||||||
Some(("uninstall", m)) => uninstall_parse(&mut flags, m),
|
Some(("uninstall", m)) => uninstall_parse(&mut flags, m),
|
||||||
|
@ -2500,20 +2496,25 @@ fn run_parse(flags: &mut Flags, matches: &clap::ArgMatches) {
|
||||||
flags.subcommand = DenoSubcommand::Run(RunFlags { script });
|
flags.subcommand = DenoSubcommand::Run(RunFlags { script });
|
||||||
}
|
}
|
||||||
|
|
||||||
fn task_parse(flags: &mut Flags, matches: &clap::ArgMatches) {
|
fn task_parse(
|
||||||
|
flags: &mut Flags,
|
||||||
|
matches: &clap::ArgMatches,
|
||||||
|
raw_args: &[String],
|
||||||
|
) {
|
||||||
config_arg_parse(flags, matches);
|
config_arg_parse(flags, matches);
|
||||||
|
|
||||||
let mut task_name = "".to_string();
|
let mut task_name = "".to_string();
|
||||||
if let Some(task) = matches.value_of("task") {
|
if let Some(task) = matches.value_of("task") {
|
||||||
task_name = task.to_string();
|
task_name = task.to_string();
|
||||||
|
|
||||||
let task_args: Vec<String> = matches
|
if let Some(task_args) = matches.values_of("task_args") {
|
||||||
.values_of("task_args")
|
// forward the `--` to the deno task
|
||||||
.unwrap_or_default()
|
if let Some(index) = matches.index_of("task_args") {
|
||||||
.map(String::from)
|
if raw_args[index] == "--" {
|
||||||
.collect();
|
flags.argv.push("--".to_string());
|
||||||
for v in task_args {
|
}
|
||||||
flags.argv.push(v);
|
}
|
||||||
|
flags.argv.extend(task_args.map(String::from));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2961,6 +2962,7 @@ pub fn resolve_urls(urls: Vec<String>) -> Vec<String> {
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
use pretty_assertions::assert_eq;
|
||||||
|
|
||||||
/// Creates vector of strings, Vec<String>
|
/// Creates vector of strings, Vec<String>
|
||||||
macro_rules! svec {
|
macro_rules! svec {
|
||||||
|
@ -5492,8 +5494,7 @@ mod tests {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn task_subcommand() {
|
fn task_subcommand() {
|
||||||
let r =
|
let r = flags_from_vec(svec!["deno", "task", "build", "hello", "world",]);
|
||||||
flags_from_vec(svec!["deno", "task", "build", "--", "hello", "world",]);
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
r.unwrap(),
|
r.unwrap(),
|
||||||
Flags {
|
Flags {
|
||||||
|
@ -5517,9 +5518,34 @@ mod tests {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn task_subcommand_double_hyphen() {
|
||||||
|
let r = flags_from_vec(svec![
|
||||||
|
"deno",
|
||||||
|
"task",
|
||||||
|
"-c",
|
||||||
|
"deno.json",
|
||||||
|
"build",
|
||||||
|
"--",
|
||||||
|
"hello",
|
||||||
|
"world",
|
||||||
|
]);
|
||||||
|
assert_eq!(
|
||||||
|
r.unwrap(),
|
||||||
|
Flags {
|
||||||
|
subcommand: DenoSubcommand::Task(TaskFlags {
|
||||||
|
task: "build".to_string(),
|
||||||
|
}),
|
||||||
|
argv: svec!["--", "hello", "world"],
|
||||||
|
config_path: Some("deno.json".to_string()),
|
||||||
|
..Flags::default()
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn task_subcommand_empty() {
|
fn task_subcommand_empty() {
|
||||||
let r = flags_from_vec(svec!["deno", "task",]);
|
let r = flags_from_vec(svec!["deno", "task"]);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
r.unwrap(),
|
r.unwrap(),
|
||||||
Flags {
|
Flags {
|
||||||
|
|
|
@ -300,7 +300,8 @@ impl TestRun {
|
||||||
) -> Result<(), AnyError> {
|
) -> Result<(), AnyError> {
|
||||||
let args = self.get_args();
|
let args = self.get_args();
|
||||||
lsp_log!("Executing test run with arguments: {}", args.join(" "));
|
lsp_log!("Executing test run with arguments: {}", args.join(" "));
|
||||||
let flags = flags::flags_from_vec(args)?;
|
let flags =
|
||||||
|
flags::flags_from_vec(args.into_iter().map(String::from).collect())?;
|
||||||
let ps = proc_state::ProcState::build(Arc::new(flags)).await?;
|
let ps = proc_state::ProcState::build(Arc::new(flags)).await?;
|
||||||
let permissions =
|
let permissions =
|
||||||
Permissions::from_options(&ps.flags.permissions_options());
|
Permissions::from_options(&ps.flags.permissions_options());
|
||||||
|
|
Loading…
Reference in a new issue