Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Print submodules in --summary #1794

Merged
merged 4 commits into from
Dec 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions src/justfile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,6 @@ pub(crate) struct 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>> {
let mut suggestions = self
.recipes
Expand Down
43 changes: 32 additions & 11 deletions src/subcommand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -533,18 +533,39 @@ impl Subcommand {
}

fn summary(config: &Config, justfile: &Justfile) {
if justfile.count() == 0 {
if config.verbosity.loud() {
eprintln!("Justfile contains no recipes.");
let mut printed = 0;
Self::summary_recursive(config, &mut Vec::new(), &mut printed, justfile);
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 {
let summary = justfile
.public_recipes(config.unsorted)
.iter()
.map(|recipe| recipe.name())
.collect::<Vec<&str>>()
.join(" ");
println!("{summary}");
if path.is_empty() {
print!("{}", recipe.name());
} else {
print!("{}::{}", path, recipe.name());
}
*printed += 1;
}

for (name, module) in &justfile.modules {
components.push(name);
Self::summary_recursive(config, components, printed, module);
components.pop();
}
}

Expand Down
1 change: 1 addition & 0 deletions tests/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ mod show;
mod slash_operator;
mod string;
mod subsequents;
mod summary;
mod tempdir;
mod undefined_variables;
mod unstable;
Expand Down
35 changes: 0 additions & 35 deletions tests/misc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,41 +187,6 @@ c: b
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! {
name: select,
justfile: "b:
Expand Down
6 changes: 0 additions & 6 deletions tests/quiet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,12 +121,6 @@ test! {
status: EXIT_FAILURE,
}

test! {
name: summary_none,
justfile: "",
args: ("--summary", "--quiet"),
}

test! {
name: quiet_shebang,
justfile: "
Expand Down
73 changes: 73 additions & 0 deletions tests/summary.rs
Original file line number Diff line number Diff line change
@@ -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();
}
Loading