mirror of
https://github.com/denoland/deno.git
synced 2024-11-21 15:04:11 -05:00
feat(flags): improve help output and make deno run
list tasks (#25108)
- 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 <biwanczuk@gmail.com>
This commit is contained in:
parent
e920835417
commit
7139337083
5 changed files with 300 additions and 222 deletions
12
Cargo.lock
generated
12
Cargo.lock
generated
|
@ -152,15 +152,16 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "anstream"
|
||||
version = "0.6.13"
|
||||
version = "0.6.15"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d96bd03f33fe50a863e394ee9718a706f988b9079b20c3784fb726e7678b62fb"
|
||||
checksum = "64e15c1ab1f89faffbf04a634d5e1962e9074f2741eef6d97f3c4e322426d526"
|
||||
dependencies = [
|
||||
"anstyle",
|
||||
"anstyle-parse",
|
||||
"anstyle-query",
|
||||
"anstyle-wincon",
|
||||
"colorchoice",
|
||||
"is_terminal_polyfill",
|
||||
"utf8parse",
|
||||
]
|
||||
|
||||
|
@ -1146,6 +1147,7 @@ dependencies = [
|
|||
name = "deno"
|
||||
version = "1.46.0-rc.3"
|
||||
dependencies = [
|
||||
"anstream",
|
||||
"async-trait",
|
||||
"base32",
|
||||
"base64 0.21.7",
|
||||
|
@ -3871,6 +3873,12 @@ dependencies = [
|
|||
"once_cell",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "is_terminal_polyfill"
|
||||
version = "1.70.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7943c866cc5cd64cbc25b2e01621d07fa8eb2a1a23160ee81ce38704e97b8ecf"
|
||||
|
||||
[[package]]
|
||||
name = "itertools"
|
||||
version = "0.10.5"
|
||||
|
|
|
@ -83,6 +83,7 @@ libsui = "0.3.0"
|
|||
napi_sym.workspace = true
|
||||
node_resolver.workspace = true
|
||||
|
||||
anstream = "0.6.14"
|
||||
async-trait.workspace = true
|
||||
base32.workspace = true
|
||||
base64.workspace = true
|
||||
|
|
File diff suppressed because it is too large
Load diff
21
cli/main.rs
21
cli/main.rs
|
@ -218,9 +218,10 @@ async fn run_subcommand(flags: Arc<Flags>) -> Result<i32, AnyError> {
|
|||
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<Flags>) -> Result<i32, AnyError> {
|
|||
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<Flags>) -> Result<i32, AnyError> {
|
|||
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),
|
||||
},
|
||||
}
|
||||
}),
|
||||
};
|
||||
|
||||
|
|
|
@ -29,13 +29,24 @@ use std::sync::Arc;
|
|||
pub async fn execute_script(
|
||||
flags: Arc<Flags>,
|
||||
task_flags: TaskFlags,
|
||||
using_run: bool,
|
||||
) -> Result<i32, AnyError> {
|
||||
let factory = CliFactory::from_flags(flags);
|
||||
let cli_options = factory.cli_options()?;
|
||||
let start_dir = &cli_options.start_dir;
|
||||
if !start_dir.has_deno_or_pkg_json() {
|
||||
bail!("deno task couldn't find deno.json(c). See https://docs.deno.com/go/config")
|
||||
if task_flags.is_run {
|
||||
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 =
|
||||
std::env::var_os(crate::task_runner::USE_PKG_JSON_HIDDEN_ENV_VAR_NAME)
|
||||
|
@ -142,7 +153,7 @@ pub async fn execute_script(
|
|||
}
|
||||
},
|
||||
None => {
|
||||
if using_run {
|
||||
if task_flags.is_run {
|
||||
return Err(anyhow!("Task not found: {}", task_name));
|
||||
}
|
||||
log::error!("Task not found: {}", task_name);
|
||||
|
|
Loading…
Reference in a new issue