Print submodule recipes in --summary (#1794)

This commit is contained in:
Casey Rodarmor 2023-12-28 19:06:48 -08:00 committed by GitHub
parent 7c2e699923
commit 3461a7f291
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 106 additions and 56 deletions

View File

@ -23,10 +23,6 @@ pub(crate) struct Justfile<'src> {
} }
impl<'src> Justfile<'src> { impl<'src> Justfile<'src> {
pub(crate) fn count(&self) -> usize {
self.recipes.len()
}
pub(crate) fn suggest_recipe(&self, input: &str) -> Option<Suggestion<'src>> { pub(crate) fn suggest_recipe(&self, input: &str) -> Option<Suggestion<'src>> {
let mut suggestions = self let mut suggestions = self
.recipes .recipes

View File

@ -533,18 +533,39 @@ impl Subcommand {
} }
fn summary(config: &Config, justfile: &Justfile) { fn summary(config: &Config, justfile: &Justfile) {
if justfile.count() == 0 { let mut printed = 0;
if config.verbosity.loud() { Self::summary_recursive(config, &mut Vec::new(), &mut printed, justfile);
eprintln!("Justfile contains no recipes."); println!();
if printed == 0 && config.verbosity.loud() {
eprintln!("Justfile contains no recipes.");
}
}
fn summary_recursive<'a>(
config: &Config,
components: &mut Vec<&'a str>,
printed: &mut usize,
justfile: &'a Justfile,
) {
let path = components.join("::");
for recipe in justfile.public_recipes(config.unsorted) {
if *printed > 0 {
print!(" ");
} }
} else { if path.is_empty() {
let summary = justfile print!("{}", recipe.name());
.public_recipes(config.unsorted) } else {
.iter() print!("{}::{}", path, recipe.name());
.map(|recipe| recipe.name()) }
.collect::<Vec<&str>>() *printed += 1;
.join(" "); }
println!("{summary}");
for (name, module) in &justfile.modules {
components.push(name);
Self::summary_recursive(config, components, printed, module);
components.pop();
} }
} }

View File

@ -87,6 +87,7 @@ mod show;
mod slash_operator; mod slash_operator;
mod string; mod string;
mod subsequents; mod subsequents;
mod summary;
mod tempdir; mod tempdir;
mod undefined_variables; mod undefined_variables;
mod unstable; mod unstable;

View File

@ -187,41 +187,6 @@ c: b
stderr: "echo a\necho b\necho c\necho d\n", stderr: "echo a\necho b\necho c\necho d\n",
} }
test! {
name: summary,
justfile: "b: a
a:
d: c
c: b
_z: _y
_y:
",
args: ("--summary"),
stdout: "a b c d\n",
}
test! {
name: summary_sorted,
justfile: "
b:
c:
a:
",
args: ("--summary"),
stdout: "a b c\n",
}
test! {
name: summary_unsorted,
justfile: "
b:
c:
a:
",
args: ("--summary", "--unsorted"),
stdout: "b c a\n",
}
test! { test! {
name: select, name: select,
justfile: "b: justfile: "b:

View File

@ -121,12 +121,6 @@ test! {
status: EXIT_FAILURE, status: EXIT_FAILURE,
} }
test! {
name: summary_none,
justfile: "",
args: ("--summary", "--quiet"),
}
test! { test! {
name: quiet_shebang, name: quiet_shebang,
justfile: " justfile: "

73
tests/summary.rs Normal file
View File

@ -0,0 +1,73 @@
use super::*;
test! {
name: summary,
justfile: "b: a
a:
d: c
c: b
_z: _y
_y:
",
args: ("--summary"),
stdout: "a b c d\n",
}
test! {
name: summary_sorted,
justfile: "
b:
c:
a:
",
args: ("--summary"),
stdout: "a b c\n",
}
test! {
name: summary_unsorted,
justfile: "
b:
c:
a:
",
args: ("--summary", "--unsorted"),
stdout: "b c a\n",
}
test! {
name: summary_none,
justfile: "",
args: ("--summary", "--quiet"),
stdout: "\n\n\n",
}
#[test]
fn no_recipes() {
Test::new()
.arg("--summary")
.stderr("Justfile contains no recipes.\n")
.stdout("\n\n\n")
.run();
}
#[test]
fn submodule_recipes() {
Test::new()
.write("foo.just", "mod bar\nfoo:")
.write("bar.just", "mod baz\nbar:")
.write("baz.just", "mod biz\nbaz:")
.write("biz.just", "biz:")
.justfile(
"
mod foo
bar:
",
)
.test_round_trip(false)
.arg("--unstable")
.arg("--summary")
.stdout("bar foo::foo foo::bar::bar foo::bar::baz::baz foo::bar::baz::biz::biz\n")
.run();
}