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

Don't display submodule recipes in --list #2112

Merged
merged 1 commit into from
May 30, 2024
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
45 changes: 13 additions & 32 deletions src/subcommand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ impl Subcommand {
Dump => Self::dump(config, ast, justfile)?,
Format => Self::format(config, &search, src, ast)?,
Groups => Self::groups(config, justfile),
List { path } => Self::list_module(config, justfile, path)?,
List { path } => Self::list(config, justfile, path)?,
Show { path } => Self::show(config, justfile, path)?,
Summary => Self::summary(config, justfile),
Variables => Self::variables(justfile),
Expand Down Expand Up @@ -479,33 +479,19 @@ impl Subcommand {
Ok(())
}

fn list_module(
config: &Config,
mut module: &Justfile,
path: &ModulePath,
) -> Result<(), Error<'static>> {
fn list(config: &Config, mut module: &Justfile, path: &ModulePath) -> Result<(), Error<'static>> {
for name in &path.path {
module = module
.modules
.get(name)
.ok_or_else(|| Error::UnknownSubmodule { path: path.clone() })?;
}

Self::list(config, 0, module);

Ok(())
}

fn list(config: &Config, level: usize, justfile: &Justfile) {
let aliases = if config.no_aliases {
BTreeMap::new()
} else {
let mut aliases = BTreeMap::<&str, Vec<&str>>::new();
for alias in justfile
.aliases
.values()
.filter(|alias| !alias.is_private())
{
for alias in module.aliases.values().filter(|alias| !alias.is_private()) {
aliases
.entry(alias.target.name.lexeme())
.or_default()
Expand All @@ -517,7 +503,7 @@ impl Subcommand {
let signature_widths = {
let mut signature_widths: BTreeMap<&str, usize> = BTreeMap::new();

for (name, recipe) in &justfile.recipes {
for (name, recipe) in &module.recipes {
if !recipe.is_public() {
continue;
}
Expand Down Expand Up @@ -545,13 +531,11 @@ impl Subcommand {
.max()
.unwrap_or(0);

if level == 0 {
print!("{}", config.list_heading);
}
print!("{}", config.list_heading);

let groups = {
let mut groups = BTreeMap::<Option<String>, Vec<&Recipe>>::new();
for recipe in justfile.public_recipes(config) {
for recipe in module.public_recipes(config) {
let recipe_groups = recipe.groups();
if recipe_groups.is_empty() {
groups.entry(None).or_default().push(recipe);
Expand All @@ -572,7 +556,7 @@ impl Subcommand {
let no_groups = groups.contains_key(&None) && groups.len() == 1;

if !no_groups {
print!("{}", config.list_prefix.repeat(level + 1));
print!("{}", config.list_prefix);
if let Some(group_name) = group {
println!("[{group_name}]");
} else {
Expand All @@ -596,7 +580,7 @@ impl Subcommand {
for line in doc.lines() {
println!(
"{}{} {}",
config.list_prefix.repeat(level + 1),
config.list_prefix,
config.color.stdout().doc().paint("#"),
config.color.stdout().doc().paint(line),
);
Expand All @@ -606,7 +590,7 @@ impl Subcommand {

print!(
"{}{}",
config.list_prefix.repeat(level + 1),
config.list_prefix,
RecipeSignature { name, recipe }.color_display(config.color.stdout())
);

Expand All @@ -626,14 +610,11 @@ impl Subcommand {
}
}

for (i, module) in justfile.modules(config).into_iter().enumerate() {
if i + groups.len() > 0 {
println!();
}

println!("{}{}:", config.list_prefix.repeat(level + 1), module.name());
Self::list(config, level + 1, module);
for submodule in module.modules(config) {
println!("{}{} ...", config.list_prefix, submodule.name(),);
}

Ok(())
}

fn show<'src>(
Expand Down
28 changes: 0 additions & 28 deletions tests/groups.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,31 +144,3 @@ fn list_groups_with_custom_prefix() {
)
.run();
}

#[test]
fn list_with_groups_in_modules() {
Test::new()
.justfile(
"
[group('FOO')]
foo:

mod bar
",
)
.write("bar.just", "[group('BAZ')]\nbaz:")
.test_round_trip(false)
.args(["--unstable", "--list"])
.stdout(
"
Available recipes:
[FOO]
foo

bar:
[BAZ]
baz
",
)
.run();
}
112 changes: 2 additions & 110 deletions tests/list.rs
Original file line number Diff line number Diff line change
@@ -1,54 +1,5 @@
use super::*;

#[test]
fn list_displays_recipes_in_submodules() {
Test::new()
.write("foo.just", "bar:\n @echo FOO")
.justfile(
"
mod foo
",
)
.test_round_trip(false)
.arg("--unstable")
.arg("--list")
.stdout(
"
Available recipes:
foo:
bar
",
)
.run();
}

#[test]
fn modules_are_space_separated_in_output() {
Test::new()
.write("foo.just", "foo:")
.write("bar.just", "bar:")
.justfile(
"
mod foo

mod bar
",
)
.test_round_trip(false)
.args(["--unstable", "--list"])
.stdout(
"
Available recipes:
bar:
bar

foo:
foo
",
)
.run();
}

#[test]
fn modules_unsorted() {
Test::new()
Expand All @@ -66,72 +17,13 @@ fn modules_unsorted() {
.stdout(
"
Available recipes:
foo:
foo

bar:
bar
",
)
.run();
}

#[test]
fn module_recipe_list_alignment_ignores_private_recipes() {
Test::new()
.write(
"foo.just",
"
# foos
foo:
@echo FOO

[private]
barbarbar:
@echo BAR

@_bazbazbaz:
@echo BAZ
",
)
.justfile("mod foo")
.test_round_trip(false)
.arg("--unstable")
.arg("--list")
.stdout(
"
Available recipes:
foo:
foo # foos
foo ...
bar ...
",
)
.run();
}

#[test]
fn nested_modules_are_properly_indented() {
Test::new()
.write("foo.just", "mod bar")
.write("bar.just", "baz:\n @echo FOO")
.justfile(
"
mod foo
",
)
.test_round_trip(false)
.arg("--unstable")
.arg("--list")
.stdout(
"
Available recipes:
foo:
bar:
baz
",
)
.run();
}

#[test]
fn unsorted_list_order() {
Test::new()
Expand Down