From 2b46af1caea0799348d98c3fff27e080d320a1cf Mon Sep 17 00:00:00 2001 From: Casey Rodarmor Date: Tue, 22 Nov 2022 16:25:57 -0800 Subject: [PATCH] Hide recipes with `[private]` attribute (#1422) --- README.md | 15 +++++++++++++++ src/attribute.rs | 1 + src/recipe.rs | 2 +- tests/lib.rs | 1 + tests/private.rs | 19 +++++++++++++++++++ 5 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 tests/private.rs diff --git a/README.md b/README.md index 4285fbc..c05dd72 100644 --- a/README.md +++ b/README.md @@ -2007,6 +2007,21 @@ $ just --summary test ``` +The `[private]` attributemaster may also be used to hide recipes without needing to change the name: + +```make +[private] +foo: + +bar: +``` + +```sh +$ just --list +Available recipes: + bar +``` + This is useful for helper recipes which are only meant to be used as dependencies of other recipes. ### Quiet Recipes diff --git a/src/attribute.rs b/src/attribute.rs index c205f34..ffd532f 100644 --- a/src/attribute.rs +++ b/src/attribute.rs @@ -10,6 +10,7 @@ pub(crate) enum Attribute { Macos, NoCd, NoExitMessage, + Private, Unix, Windows, } diff --git a/src/recipe.rs b/src/recipe.rs index 5fda449..fa0aedb 100644 --- a/src/recipe.rs +++ b/src/recipe.rs @@ -63,7 +63,7 @@ impl<'src, D> Recipe<'src, D> { } pub(crate) fn public(&self) -> bool { - !self.private + !self.private && !self.attributes.contains(&Attribute::Private) } pub(crate) fn change_directory(&self) -> bool { diff --git a/tests/lib.rs b/tests/lib.rs index e6c7ed4..11d4d19 100644 --- a/tests/lib.rs +++ b/tests/lib.rs @@ -65,6 +65,7 @@ mod no_exit_message; mod os_attributes; mod parser; mod positional_arguments; +mod private; mod quiet; mod quote; mod readme; diff --git a/tests/private.rs b/tests/private.rs new file mode 100644 index 0000000..82e3d4f --- /dev/null +++ b/tests/private.rs @@ -0,0 +1,19 @@ +use super::*; + +#[test] +fn attribute() { + Test::new() + .justfile( + " + [private] + foo: + ", + ) + .args(&["--list"]) + .stdout( + " + Available recipes: + ", + ) + .run(); +}