From 710f95a9b15c311958ad160c0bfc1de5d4744892 Mon Sep 17 00:00:00 2001 From: Adam Snaider Date: Sun, 4 Aug 2024 21:47:34 -0400 Subject: [PATCH] Hide private variables from evaluate --- src/justfile.rs | 14 ++++++++------ tests/evaluate.rs | 17 +++++++++++++++++ 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/src/justfile.rs b/src/justfile.rs index b31084ef18..0f1b779836 100644 --- a/src/justfile.rs +++ b/src/justfile.rs @@ -164,12 +164,14 @@ impl<'src> Justfile<'src> { let width = scope.names().fold(0, |max, name| name.len().max(max)); for binding in scope.bindings() { - println!( - "{0:1$} := \"{2}\"", - binding.name.lexeme(), - width, - binding.value - ); + if !self.settings.allow_private_variables || binding.is_public() { + println!( + "{0:1$} := \"{2}\"", + binding.name.lexeme(), + width, + binding.value + ); + } } } diff --git a/tests/evaluate.rs b/tests/evaluate.rs index b74c6b356b..e7cf2eb822 100644 --- a/tests/evaluate.rs +++ b/tests/evaluate.rs @@ -80,6 +80,21 @@ test! { test! { name: evaluate_private, + justfile: " + set allow-private-variables + + [private] + foo := 'one' + bar := 'two' + _baz := 'three' + ", + args: ("--evaluate"), + stdout: "bar := \"two\"\n", + status: EXIT_SUCCESS, +} + +test! { + name: evaluate_private_not_enabled, justfile: " [private] foo := 'one' @@ -94,6 +109,8 @@ test! { test! { name: evaluate_single_private, justfile: " + set allow-private-variables + [private] foo := 'one' bar := 'two'