diff options
author | Nathan Whitaker <17734409+nathanwhit@users.noreply.github.com> | 2024-03-27 14:14:27 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-03-27 14:14:27 -0700 |
commit | 2dc37f411e8947d3c20cd93d1fa1937edc239499 (patch) | |
tree | 0ecb10fb3cc0e9085130c3683155529c5de74e84 /cli/tools/task.rs | |
parent | 68fecc6de4b2e6556adeb2730798bf42017c4be6 (diff) |
feat(task): Task description in the form of comments (#23101)
Closes #22786.
TLDR;
```jsonc
{
"tasks": {
// Some comment
//
// describing what the task does
"dev": "deno run -A --watch main.ts"
}
}
```
```bash
deno task
```

Diffstat (limited to 'cli/tools/task.rs')
-rw-r--r-- | cli/tools/task.rs | 38 |
1 files changed, 29 insertions, 9 deletions
diff --git a/cli/tools/task.rs b/cli/tools/task.rs index 8f500df34..5eefda73f 100644 --- a/cli/tools/task.rs +++ b/cli/tools/task.rs @@ -49,7 +49,13 @@ pub async fn execute_script( } }; - if let Some(script) = tasks_config.get(task_name) { + if let Some( + deno_config::Task::Definition(script) + | deno_config::Task::Commented { + definition: script, .. + }, + ) = tasks_config.get(task_name) + { let config_file_url = cli_options.maybe_config_file_specifier().unwrap(); let config_file_path = if config_file_url.scheme() == "file" { config_file_url.to_file_path().unwrap() @@ -222,18 +228,22 @@ fn collect_env_vars() -> HashMap<String, String> { fn print_available_tasks( // order can be important, so these use an index map - tasks_config: &IndexMap<String, String>, + tasks_config: &IndexMap<String, deno_config::Task>, package_json_scripts: &IndexMap<String, String>, ) { eprintln!("{}", colors::green("Available tasks:")); let mut had_task = false; - for (is_deno, (key, value)) in tasks_config.iter().map(|e| (true, e)).chain( - package_json_scripts - .iter() - .filter(|(key, _)| !tasks_config.contains_key(*key)) - .map(|e| (false, e)), - ) { + for (is_deno, (key, task)) in tasks_config + .iter() + .map(|(k, t)| (true, (k, t.clone()))) + .chain( + package_json_scripts + .iter() + .filter(|(key, _)| !tasks_config.contains_key(*key)) + .map(|(k, v)| (false, (k, deno_config::Task::Definition(v.clone())))), + ) + { eprintln!( "- {}{}", colors::cyan(key), @@ -243,7 +253,17 @@ fn print_available_tasks( format!(" {}", colors::italic_gray("(package.json)")) } ); - eprintln!(" {value}"); + let definition = match &task { + deno_config::Task::Definition(definition) => definition, + deno_config::Task::Commented { definition, .. } => definition, + }; + if let deno_config::Task::Commented { comments, .. } = &task { + let slash_slash = colors::italic_gray("//"); + for comment in comments { + eprintln!(" {slash_slash} {}", colors::italic_gray(comment)); + } + } + eprintln!(" {definition}"); had_task = true; } if !had_task { |