From 71393370832946a33e8a34d2e9cfaad8bf97c91b Mon Sep 17 00:00:00 2001 From: Leo Kettmeir Date: Wed, 21 Aug 2024 06:54:59 -0700 Subject: feat(flags): improve help output and make `deno run` list tasks (#25108) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - rewrite flag help - use gray for indentation - reorganize permission flags and split them up - make help subcommand act like help flag - `deno run` outputs list of tasks - Fixes #25120 error handling for `deno run` in case of no config file being found needs to be improved --------- Co-authored-by: Bartek IwaƄczuk --- cli/main.rs | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) (limited to 'cli/main.rs') diff --git a/cli/main.rs b/cli/main.rs index 6a7575dee..290eee120 100644 --- a/cli/main.rs +++ b/cli/main.rs @@ -218,9 +218,10 @@ async fn run_subcommand(flags: Arc) -> Result { let task_flags = TaskFlags { cwd: None, task: Some(run_flags.script.clone()), + is_run: true, }; new_flags.subcommand = DenoSubcommand::Task(task_flags.clone()); - let result = tools::task::execute_script(Arc::new(new_flags), task_flags.clone(), true).await; + let result = tools::task::execute_script(Arc::new(new_flags), task_flags.clone()).await; match result { Ok(v) => Ok(v), Err(_) => { @@ -240,7 +241,7 @@ async fn run_subcommand(flags: Arc) -> Result { tools::serve::serve(flags, serve_flags).await }), DenoSubcommand::Task(task_flags) => spawn_subcommand(async { - tools::task::execute_script(flags, task_flags, false).await + tools::task::execute_script(flags, task_flags).await }), DenoSubcommand::Test(test_flags) => { spawn_subcommand(async { @@ -290,7 +291,21 @@ async fn run_subcommand(flags: Arc) -> Result { tools::registry::publish(flags, publish_flags).await }), DenoSubcommand::Help(help_flags) => spawn_subcommand(async move { - display::write_to_stdout_ignore_sigpipe(help_flags.help.ansi().to_string().as_bytes()) + use std::io::Write; + + let mut stream = anstream::AutoStream::new(std::io::stdout(), if colors::use_color() { + anstream::ColorChoice::Auto + } else { + anstream::ColorChoice::Never + }); + + match stream.write_all(help_flags.help.ansi().to_string().as_bytes()) { + Ok(()) => Ok(()), + Err(e) => match e.kind() { + std::io::ErrorKind::BrokenPipe => Ok(()), + _ => Err(e), + }, + } }), }; -- cgit v1.2.3