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

fix(flags): don't treat empty run command as task subcommand (#25708)

This commit is contained in:
Leo Kettmeir 2024-09-18 11:36:37 -07:00 committed by GitHub
parent 49a0b7ab93
commit c90b074579
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 22 additions and 20 deletions

View file

@ -4679,7 +4679,7 @@ fn repl_parse(
fn run_parse( fn run_parse(
flags: &mut Flags, flags: &mut Flags,
matches: &mut ArgMatches, matches: &mut ArgMatches,
app: Command, mut app: Command,
bare: bool, bare: bool,
) -> clap::error::Result<()> { ) -> clap::error::Result<()> {
runtime_args_parse(flags, matches, true, true)?; runtime_args_parse(flags, matches, true, true)?;
@ -4701,11 +4701,16 @@ fn run_parse(
"[SCRIPT_ARG] may only be omitted with --v8-flags=--help, else to use the repl with arguments, please use the `deno repl` subcommand", "[SCRIPT_ARG] may only be omitted with --v8-flags=--help, else to use the repl with arguments, please use the `deno repl` subcommand",
)); ));
} else { } else {
flags.subcommand = DenoSubcommand::Task(TaskFlags { return Err(
cwd: None, app
task: None, .get_subcommands_mut()
is_run: true, .find(|subcommand| subcommand.get_name() == "run")
}); .unwrap()
.error(
clap::error::ErrorKind::MissingRequiredArgument,
"[SCRIPT_ARG] may only be omitted with --v8-flags=--help",
),
);
} }
Ok(()) Ok(())
@ -5927,7 +5932,7 @@ mod tests {
); );
let r = flags_from_vec(svec!["deno", "run", "--v8-flags=--expose-gc"]); let r = flags_from_vec(svec!["deno", "run", "--v8-flags=--expose-gc"]);
assert!(r.is_ok()); assert!(r.is_err());
} }
#[test] #[test]

View file

@ -36,19 +36,7 @@ pub async fn execute_script(
let cli_options = factory.cli_options()?; let cli_options = factory.cli_options()?;
let start_dir = &cli_options.start_dir; let start_dir = &cli_options.start_dir;
if !start_dir.has_deno_or_pkg_json() { if !start_dir.has_deno_or_pkg_json() {
if task_flags.is_run { bail!("deno task couldn't find deno.json(c). See https://docs.deno.com/go/config")
bail!(
r#"deno run couldn't find deno.json(c).
If you meant to run a script, specify it, e.g., `deno run ./script.ts`.
To run a task, ensure the config file exists.
Examples:
- Script: `deno run ./script.ts`
- Task: `deno run dev`
See https://docs.deno.com/go/config"#
)
} else {
bail!("deno task couldn't find deno.json(c). See https://docs.deno.com/go/config")
}
} }
let force_use_pkg_json = let force_use_pkg_json =
std::env::var_os(crate::task_runner::USE_PKG_JSON_HIDDEN_ENV_VAR_NAME) std::env::var_os(crate::task_runner::USE_PKG_JSON_HIDDEN_ENV_VAR_NAME)

View file

@ -1,5 +1,10 @@
{ {
"tests": { "tests": {
"deno_run_empty": {
"args": "run",
"output": "empty.out",
"exitCode": 1
},
"deno_run_task": { "deno_run_task": {
"args": "run main", "args": "run main",
"output": "main.out" "output": "main.out"

View file

@ -0,0 +1,4 @@
error: [SCRIPT_ARG] may only be omitted with --v8-flags=--help
Usage: deno run [OPTIONS] [SCRIPT_ARG]...