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)?,
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),
@ -479,11 +479,7 @@ 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
@ -491,21 +487,11 @@ impl Subcommand {
.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()
@ -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;
}
@ -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);
@ -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 {
@ -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),
);
@ -606,7 +590,7 @@ impl Subcommand {
print!(
"{}{}",
config.list_prefix.repeat(level + 1),
config.list_prefix,
RecipeSignature { name, recipe }.color_display(config.color.stdout())
);
@ -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>(

View File

@ -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();
}

View File

@ -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()
@ -66,72 +17,13 @@ fn modules_unsorted() {
.stdout(
"
Available recipes:
foo:
foo
bar:
bar
foo ...
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
",
)
.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()