Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
39 changes: 34 additions & 5 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 @@ -5745,7 +5747,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 @@ -5764,6 +5766,7 @@ fn run_parse(
watch: watch_arg_parse_with_paths(matches)?,
bare,
coverage_dir,
print_task_list: false,
});
}
_ => {
Expand All @@ -5773,10 +5776,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 @@ -6743,6 +6750,7 @@ mod tests {
}),
bare: false,
coverage_dir: None,
print_task_list: false,
}),
code_cache_enabled: true,
..Flags::default()
Expand All @@ -6769,6 +6777,7 @@ mod tests {
}),
bare: true,
coverage_dir: None,
print_task_list: false,
}),
code_cache_enabled: true,
..Flags::default()
Expand Down Expand Up @@ -6796,6 +6805,7 @@ mod tests {
}),
bare: false,
coverage_dir: None,
print_task_list: false,
}),
code_cache_enabled: true,
..Flags::default()
Expand Down Expand Up @@ -6823,6 +6833,7 @@ mod tests {
}),
bare: false,
coverage_dir: None,
print_task_list: false,
}),
code_cache_enabled: true,
..Flags::default()
Expand Down Expand Up @@ -6850,6 +6861,7 @@ mod tests {
}),
bare: false,
coverage_dir: None,
print_task_list: false,
}),
code_cache_enabled: true,
..Flags::default()
Expand Down Expand Up @@ -6878,6 +6890,7 @@ mod tests {
}),
bare: true,
coverage_dir: None,
print_task_list: false,
}),
code_cache_enabled: true,
..Flags::default()
Expand Down Expand Up @@ -6909,6 +6922,7 @@ mod tests {
}),
bare: false,
coverage_dir: None,
print_task_list: false,
}),
code_cache_enabled: true,
..Flags::default()
Expand Down Expand Up @@ -6939,6 +6953,7 @@ mod tests {
}),
bare: true,
coverage_dir: None,
print_task_list: false,
}),
code_cache_enabled: true,
..Flags::default()
Expand Down Expand Up @@ -6966,6 +6981,7 @@ mod tests {
}),
bare: false,
coverage_dir: None,
print_task_list: false,
}),
code_cache_enabled: true,
..Flags::default()
Expand Down Expand Up @@ -6994,6 +7010,7 @@ mod tests {
}),
bare: false,
coverage_dir: None,
print_task_list: false,
}),
code_cache_enabled: true,
..Flags::default()
Expand Down Expand Up @@ -7021,6 +7038,7 @@ mod tests {
}),
bare: true,
coverage_dir: None,
print_task_list: false,
}),
code_cache_enabled: true,
..Flags::default()
Expand Down Expand Up @@ -7060,6 +7078,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 @@ -7376,6 +7395,7 @@ mod tests {
watch: None,
bare: true,
coverage_dir: None,
print_task_list: false,
}),
permissions: PermissionFlags {
deny_read: Some(vec![]),
Expand Down Expand Up @@ -8666,6 +8686,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 @@ -8854,6 +8875,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 @@ -9154,6 +9176,7 @@ mod tests {
watch: None,
bare: true,
coverage_dir: None,
print_task_list: false,
}),
..Flags::default()
}
Expand Down Expand Up @@ -9465,6 +9488,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 @@ -9586,6 +9610,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 @@ -9758,6 +9783,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 @@ -10982,6 +11008,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 @@ -11676,6 +11703,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 @@ -12230,6 +12258,7 @@ mod tests {
watch: None,
bare: true,
coverage_dir: None,
print_task_list: false,
}),
config_flag: ConfigFlag::Disabled,
code_cache_enabled: true,
Expand Down
23 changes: 22 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,27 @@ 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 {
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(
flags,
TaskFlags {
cwd: None,
task: None,
is_run: true,
recursive: false,
filter: None,
eval: false,
},
)
.await
} 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
5 changes: 5 additions & 0 deletions tests/specs/run/run_without_script_argument/__test__.jsonc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"args": "run -q --config deno.json",
"output": "run_without_script_argument.out",
"exitCode": 0
}
9 changes: 9 additions & 0 deletions tests/specs/run/run_without_script_argument/deno.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"tasks": {
"dev": "deno run --watch --allow-net server.ts",
"test": "deno test --allow-read tests/",
"build": "deno compile --allow-net --output=./dist/app server.ts",
"lint": "deno lint",
"fmt": "deno fmt"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Please specify a [SCRIPT_ARG] or a task name.

Available tasks:
- dev
deno run --watch --allow-net server.ts
- test
deno test --allow-read tests/
- build
deno compile --allow-net --output=./dist/app server.ts
- lint
deno lint
- fmt
deno fmt
Loading