Print multi-line doc comments before recipe in --list (#2090)

This commit is contained in:
Casey Rodarmor 2024-05-25 18:12:55 -07:00 committed by GitHub
parent 16a27dba87
commit 2bacbddadb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 55 additions and 18 deletions

View File

@ -566,26 +566,41 @@ impl Subcommand {
.chain(aliases.get(recipe.name()).unwrap_or(&Vec::new())) .chain(aliases.get(recipe.name()).unwrap_or(&Vec::new()))
.enumerate() .enumerate()
{ {
print!(
"{}{}",
config.list_prefix.repeat(level + 1),
RecipeSignature { name, recipe }.color_display(config.color.stdout())
);
let doc = if i == 0 { let doc = if i == 0 {
recipe.doc().map(Cow::Borrowed) recipe.doc().map(Cow::Borrowed)
} else { } else {
Some(Cow::Owned(format!("alias for `{}`", recipe.name))) Some(Cow::Owned(format!("alias for `{}`", recipe.name)))
}; };
if let Some(doc) = &doc {
if doc.lines().count() > 1 {
for line in doc.lines() {
println!(
"{}{} {}",
config.list_prefix.repeat(level + 1),
config.color.stdout().doc().paint("#"),
config.color.stdout().doc().paint(line),
);
}
}
}
print!(
"{}{}",
config.list_prefix.repeat(level + 1),
RecipeSignature { name, recipe }.color_display(config.color.stdout())
);
if let Some(doc) = doc { if let Some(doc) = doc {
print!( if doc.lines().count() <= 1 {
"{:padding$}{} {}", print!(
"", "{:padding$}{} {}",
config.color.stdout().doc().paint("#"), "",
config.color.stdout().doc().paint(&doc), config.color.stdout().doc().paint("#"),
padding = max_signature_width.saturating_sub(signature_widths[name]) + 1, config.color.stdout().doc().paint(&doc),
); padding = max_signature_width.saturating_sub(signature_widths[name]) + 1,
);
}
} }
println!(); println!();
} }

View File

@ -156,11 +156,11 @@ fn doc_attribute_suppress() {
Test::new() Test::new()
.justfile( .justfile(
" "
# Non-document comment # Non-document comment
[doc] [doc]
foo: foo:
echo foo echo foo
", ",
) )
.args(["--list"]) .args(["--list"])
.stdout( .stdout(
@ -171,3 +171,25 @@ fn doc_attribute_suppress() {
) )
.run(); .run();
} }
#[test]
fn doc_multiline() {
Test::new()
.justfile(
"
[doc('multiline
comment')]
foo:
",
)
.args(["--list"])
.stdout(
"
Available recipes:
# multiline
# comment
foo
",
)
.run();
}