From f5bb82dea3edde07b5aca4303e2d73a300f45d5e Mon Sep 17 00:00:00 2001 From: Casey Rodarmor Date: Wed, 29 May 2024 21:15:10 -0500 Subject: [PATCH] Don't display submodule recipes in `--list` (#2112) --- src/subcommand.rs | 45 ++++++------------- tests/groups.rs | 28 ------------ tests/list.rs | 112 +--------------------------------------------- 3 files changed, 15 insertions(+), 170 deletions(-) diff --git a/src/subcommand.rs b/src/subcommand.rs index 9cf24e3..c2ec213 100644 --- a/src/subcommand.rs +++ b/src/subcommand.rs @@ -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::, 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>( diff --git a/tests/groups.rs b/tests/groups.rs index 630d780..6c072e8 100644 --- a/tests/groups.rs +++ b/tests/groups.rs @@ -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(); -} diff --git a/tests/list.rs b/tests/list.rs index 7ee5d46..e8002b1 100644 --- a/tests/list.rs +++ b/tests/list.rs @@ -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()