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

This commit is contained in:
Casey Rodarmor 2024-05-29 21:15:10 -05:00 committed by GitHub
parent de1256f1bd
commit f5bb82dea3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 15 additions and 170 deletions

View File

@ -90,7 +90,7 @@ impl Subcommand {
Dump => Self::dump(config, ast, justfile)?, Dump => Self::dump(config, ast, justfile)?,
Format => Self::format(config, &search, src, ast)?, Format => Self::format(config, &search, src, ast)?,
Groups => Self::groups(config, justfile), 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)?, Show { path } => Self::show(config, justfile, path)?,
Summary => Self::summary(config, justfile), Summary => Self::summary(config, justfile),
Variables => Self::variables(justfile), Variables => Self::variables(justfile),
@ -479,11 +479,7 @@ impl Subcommand {
Ok(()) Ok(())
} }
fn list_module( fn list(config: &Config, mut module: &Justfile, path: &ModulePath) -> Result<(), Error<'static>> {
config: &Config,
mut module: &Justfile,
path: &ModulePath,
) -> Result<(), Error<'static>> {
for name in &path.path { for name in &path.path {
module = module module = module
.modules .modules
@ -491,21 +487,11 @@ impl Subcommand {
.ok_or_else(|| Error::UnknownSubmodule { path: path.clone() })?; .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 { let aliases = if config.no_aliases {
BTreeMap::new() BTreeMap::new()
} else { } else {
let mut aliases = BTreeMap::<&str, Vec<&str>>::new(); let mut aliases = BTreeMap::<&str, Vec<&str>>::new();
for alias in justfile for alias in module.aliases.values().filter(|alias| !alias.is_private()) {
.aliases
.values()
.filter(|alias| !alias.is_private())
{
aliases aliases
.entry(alias.target.name.lexeme()) .entry(alias.target.name.lexeme())
.or_default() .or_default()
@ -517,7 +503,7 @@ impl Subcommand {
let signature_widths = { let signature_widths = {
let mut signature_widths: BTreeMap<&str, usize> = BTreeMap::new(); 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() { if !recipe.is_public() {
continue; continue;
} }
@ -545,13 +531,11 @@ impl Subcommand {
.max() .max()
.unwrap_or(0); .unwrap_or(0);
if level == 0 { print!("{}", config.list_heading);
print!("{}", config.list_heading);
}
let groups = { let groups = {
let mut groups = BTreeMap::<Option<String>, Vec<&Recipe>>::new(); 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(); let recipe_groups = recipe.groups();
if recipe_groups.is_empty() { if recipe_groups.is_empty() {
groups.entry(None).or_default().push(recipe); groups.entry(None).or_default().push(recipe);
@ -572,7 +556,7 @@ impl Subcommand {
let no_groups = groups.contains_key(&None) && groups.len() == 1; let no_groups = groups.contains_key(&None) && groups.len() == 1;
if !no_groups { if !no_groups {
print!("{}", config.list_prefix.repeat(level + 1)); print!("{}", config.list_prefix);
if let Some(group_name) = group { if let Some(group_name) = group {
println!("[{group_name}]"); println!("[{group_name}]");
} else { } else {
@ -596,7 +580,7 @@ impl Subcommand {
for line in doc.lines() { for line in doc.lines() {
println!( println!(
"{}{} {}", "{}{} {}",
config.list_prefix.repeat(level + 1), config.list_prefix,
config.color.stdout().doc().paint("#"), config.color.stdout().doc().paint("#"),
config.color.stdout().doc().paint(line), config.color.stdout().doc().paint(line),
); );
@ -606,7 +590,7 @@ impl Subcommand {
print!( print!(
"{}{}", "{}{}",
config.list_prefix.repeat(level + 1), config.list_prefix,
RecipeSignature { name, recipe }.color_display(config.color.stdout()) RecipeSignature { name, recipe }.color_display(config.color.stdout())
); );
@ -626,14 +610,11 @@ impl Subcommand {
} }
} }
for (i, module) in justfile.modules(config).into_iter().enumerate() { for submodule in module.modules(config) {
if i + groups.len() > 0 { println!("{}{} ...", config.list_prefix, submodule.name(),);
println!();
}
println!("{}{}:", config.list_prefix.repeat(level + 1), module.name());
Self::list(config, level + 1, module);
} }
Ok(())
} }
fn show<'src>( fn show<'src>(

View File

@ -144,31 +144,3 @@ fn list_groups_with_custom_prefix() {
) )
.run(); .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();
}

View File

@ -1,54 +1,5 @@
use super::*; 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] #[test]
fn modules_unsorted() { fn modules_unsorted() {
Test::new() Test::new()
@ -66,72 +17,13 @@ fn modules_unsorted() {
.stdout( .stdout(
" "
Available recipes: Available recipes:
foo: foo ...
foo bar ...
bar:
bar
", ",
) )
.run(); .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
",
)
.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] #[test]
fn unsorted_list_order() { fn unsorted_list_order() {
Test::new() Test::new()