Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 35 additions & 6 deletions cli/args/flags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,7 @@ pub struct RunFlags {
pub watch: Option<WatchFlagsWithPaths>,
pub bare: bool,
pub coverage_dir: Option<String>,
pub print_task_list: bool,
}

impl RunFlags {
Expand All @@ -349,6 +350,7 @@ impl RunFlags {
watch: None,
bare: false,
coverage_dir: None,
print_task_list: false,
}
}

Expand Down Expand Up @@ -5763,7 +5765,7 @@ fn repl_parse(
fn run_parse(
flags: &mut Flags,
matches: &mut ArgMatches,
mut app: Command,
app: Command,
bare: bool,
) -> clap::error::Result<()> {
runtime_args_parse(flags, matches, true, true, true)?;
Expand All @@ -5782,6 +5784,7 @@ fn run_parse(
watch: watch_arg_parse_with_paths(matches)?,
bare,
coverage_dir,
print_task_list: false,
});
}
_ => {
Expand All @@ -5791,10 +5794,14 @@ 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",
));
} else {
return Err(app.find_subcommand_mut("run").unwrap().error(
clap::error::ErrorKind::MissingRequiredArgument,
"[SCRIPT_ARG] may only be omitted with --v8-flags=--help",
));
// When no script argument is provided, show available tasks like `deno task`
flags.subcommand = DenoSubcommand::Run(RunFlags {
script: "".to_string(),
watch: None,
bare: false,
coverage_dir: None,
print_task_list: true,
});
}
}
}
Expand Down Expand Up @@ -6764,6 +6771,7 @@ mod tests {
}),
bare: false,
coverage_dir: None,
print_task_list: false,
}),
code_cache_enabled: true,
..Flags::default()
Expand All @@ -6790,6 +6798,7 @@ mod tests {
}),
bare: true,
coverage_dir: None,
print_task_list: false,
}),
code_cache_enabled: true,
..Flags::default()
Expand Down Expand Up @@ -6817,6 +6826,7 @@ mod tests {
}),
bare: false,
coverage_dir: None,
print_task_list: false,
}),
code_cache_enabled: true,
..Flags::default()
Expand Down Expand Up @@ -6844,6 +6854,7 @@ mod tests {
}),
bare: false,
coverage_dir: None,
print_task_list: false,
}),
code_cache_enabled: true,
..Flags::default()
Expand Down Expand Up @@ -6871,6 +6882,7 @@ mod tests {
}),
bare: false,
coverage_dir: None,
print_task_list: false,
}),
code_cache_enabled: true,
..Flags::default()
Expand Down Expand Up @@ -6899,6 +6911,7 @@ mod tests {
}),
bare: true,
coverage_dir: None,
print_task_list: false,
}),
code_cache_enabled: true,
..Flags::default()
Expand Down Expand Up @@ -6930,6 +6943,7 @@ mod tests {
}),
bare: false,
coverage_dir: None,
print_task_list: false,
}),
code_cache_enabled: true,
..Flags::default()
Expand Down Expand Up @@ -6960,6 +6974,7 @@ mod tests {
}),
bare: true,
coverage_dir: None,
print_task_list: false,
}),
code_cache_enabled: true,
..Flags::default()
Expand Down Expand Up @@ -6987,6 +7002,7 @@ mod tests {
}),
bare: false,
coverage_dir: None,
print_task_list: false,
}),
code_cache_enabled: true,
..Flags::default()
Expand Down Expand Up @@ -7015,6 +7031,7 @@ mod tests {
}),
bare: false,
coverage_dir: None,
print_task_list: false,
}),
code_cache_enabled: true,
..Flags::default()
Expand Down Expand Up @@ -7042,6 +7059,7 @@ mod tests {
}),
bare: true,
coverage_dir: None,
print_task_list: false,
}),
code_cache_enabled: true,
..Flags::default()
Expand Down Expand Up @@ -7081,6 +7099,7 @@ mod tests {
watch: None,
bare: false,
coverage_dir: Some("foo".to_string()),
print_task_list: false,
}),
code_cache_enabled: true,
..Flags::default()
Expand Down Expand Up @@ -7120,7 +7139,7 @@ mod tests {
);

let r = flags_from_vec(svec!["deno", "run", "--v8-flags=--expose-gc"]);
assert!(r.is_err());
assert!(r.is_ok());
}

#[test]
Expand Down Expand Up @@ -7397,6 +7416,7 @@ mod tests {
watch: None,
bare: true,
coverage_dir: None,
print_task_list: false,
}),
permissions: PermissionFlags {
deny_read: Some(vec![]),
Expand Down Expand Up @@ -8687,6 +8707,7 @@ mod tests {
watch: None,
bare: true,
coverage_dir: None,
print_task_list: false,
}),
permissions: PermissionFlags {
deny_net: Some(svec!["127.0.0.1"]),
Expand Down Expand Up @@ -8875,6 +8896,7 @@ mod tests {
watch: None,
bare: true,
coverage_dir: None,
print_task_list: false,
}),
permissions: PermissionFlags {
deny_sys: Some(svec!["hostname"]),
Expand Down Expand Up @@ -9175,6 +9197,7 @@ mod tests {
watch: None,
bare: true,
coverage_dir: None,
print_task_list: false,
}),
..Flags::default()
}
Expand Down Expand Up @@ -9486,6 +9509,7 @@ mod tests {
watch: None,
bare: true,
coverage_dir: None,
print_task_list: false,
}),
log_level: Some(Level::Error),
code_cache_enabled: true,
Expand Down Expand Up @@ -9607,6 +9631,7 @@ mod tests {
watch: None,
bare: true,
coverage_dir: None,
print_task_list: false,
}),
type_check_mode: TypeCheckMode::None,
code_cache_enabled: true,
Expand Down Expand Up @@ -9779,6 +9804,7 @@ mod tests {
watch: None,
bare: true,
coverage_dir: None,
print_task_list: false,
}),
node_modules_dir: Some(NodeModulesDirMode::Auto),
code_cache_enabled: true,
Expand Down Expand Up @@ -11003,6 +11029,7 @@ mod tests {
watch: None,
bare: true,
coverage_dir: None,
print_task_list: false,
}),
inspect_wait: Some("127.0.0.1:9229".parse().unwrap()),
code_cache_enabled: true,
Expand Down Expand Up @@ -11697,6 +11724,7 @@ mod tests {
watch: None,
bare: true,
coverage_dir: None,
print_task_list: false,
}),
type_check_mode: TypeCheckMode::None,
code_cache_enabled: true,
Expand Down Expand Up @@ -12251,6 +12279,7 @@ mod tests {
watch: None,
bare: true,
coverage_dir: None,
print_task_list: false,
}),
config_flag: ConfigFlag::Disabled,
code_cache_enabled: true,
Expand Down
24 changes: 23 additions & 1 deletion cli/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ use std::collections::HashMap;
use std::env;
use std::future::Future;
use std::io::IsTerminal;
use std::io::Write as _;
use std::ops::Deref;
use std::path::PathBuf;
use std::sync::Arc;
Expand Down Expand Up @@ -241,7 +242,28 @@ async fn run_subcommand(
spawn_subcommand(async move { tools::repl::run(flags, repl_flags).await })
}
DenoSubcommand::Run(run_flags) => spawn_subcommand(async move {
if run_flags.is_stdin() {
if run_flags.print_task_list {
let task_flags = TaskFlags {
cwd: None,
task: None,
is_run: true,
recursive: false,
filter: None,
eval: false,
};
let mut flags = flags.deref().clone();
flags.subcommand = DenoSubcommand::Task(task_flags.clone());
writeln!(
&mut std::io::stdout(),
"Please specify a {} or a {}.\n",
colors::bold("[SCRIPT_ARG]"),
colors::bold("task name")
)?;
std::io::stdout().flush()?;
tools::task::execute_script(Arc::new(flags), task_flags)
.await
.map(|_| 1)
} else if run_flags.is_stdin() {
// these futures are boxed to prevent stack overflows on Windows
tools::run::run_from_stdin(flags.clone(), unconfigured_runtime, roots)
.boxed_local()
Expand Down
2 changes: 1 addition & 1 deletion cli/tools/task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ pub async fn execute_script(
let start_dir = &cli_options.start_dir;
if !start_dir.has_deno_or_pkg_json() && !task_flags.eval {
bail!(
"deno task couldn't find deno.json(c). See https://docs.deno.com/go/config"
"deno task couldn't find deno.json(c) or package.json. See https://docs.deno.com/go/config"
)
}
let force_use_pkg_json =
Expand Down
9 changes: 6 additions & 3 deletions tests/specs/run/run_task/empty.out
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
error: [SCRIPT_ARG] may only be omitted with --v8-flags=--help

Usage: deno run [OPTIONS] [SCRIPT_ARG]...
Please specify a [SCRIPT_ARG] or a task name.

Available tasks:
- main
deno run main.ts
- main:foo
deno run main.ts
Loading