From 541e78104c6d9030f35751bcf6c59e85574314d3 Mon Sep 17 00:00:00 2001 From: crdx Date: Tue, 9 Jan 2024 08:07:43 +0000 Subject: [PATCH] Ignore [private] recipes in just --list (#1816) --- src/justfile.rs | 2 +- src/recipe.rs | 2 +- src/subcommand.rs | 2 +- tests/modules.rs | 31 +++++++++++++++++++++++++++++++ 4 files changed, 34 insertions(+), 3 deletions(-) diff --git a/src/justfile.rs b/src/justfile.rs index 55cc70df..0b862d29 100644 --- a/src/justfile.rs +++ b/src/justfile.rs @@ -468,7 +468,7 @@ impl<'src> Justfile<'src> { .recipes .values() .map(AsRef::as_ref) - .filter(|recipe| recipe.public()) + .filter(|recipe| recipe.is_public()) .collect::>>(); if source_order { diff --git a/src/recipe.rs b/src/recipe.rs index 30e9d9ed..8f91bb01 100644 --- a/src/recipe.rs +++ b/src/recipe.rs @@ -94,7 +94,7 @@ impl<'src, D> Recipe<'src, D> { Ok(()) } - pub(crate) fn public(&self) -> bool { + pub(crate) fn is_public(&self) -> bool { !self.private && !self.attributes.contains(&Attribute::Private) } diff --git a/src/subcommand.rs b/src/subcommand.rs index ad016eb1..8dbcbaea 100644 --- a/src/subcommand.rs +++ b/src/subcommand.rs @@ -445,7 +445,7 @@ impl Subcommand { let mut line_widths: BTreeMap<&str, usize> = BTreeMap::new(); for (name, recipe) in &justfile.recipes { - if recipe.private { + if !recipe.is_public() { continue; } diff --git a/tests/modules.rs b/tests/modules.rs index 63e067fe..75aaf7fc 100644 --- a/tests/modules.rs +++ b/tests/modules.rs @@ -685,6 +685,37 @@ fn module_paths_beginning_with_tilde_are_expanded_to_homdir() { .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 recipes_with_same_name_are_both_run() { Test::new()