Skip to content

Commit

Permalink
Hide private variables from evaluate
Browse files Browse the repository at this point in the history
  • Loading branch information
adsnaider committed Aug 10, 2024
1 parent e591af7 commit 710f95a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/justfile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
}
}
}

Expand Down
17 changes: 17 additions & 0 deletions tests/evaluate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -94,6 +109,8 @@ test! {
test! {
name: evaluate_single_private,
justfile: "
set allow-private-variables
[private]
foo := 'one'
bar := 'two'
Expand Down

0 comments on commit 710f95a

Please sign in to comment.