From 5e395dbdfe3e78b691c87737a074a84f8b203b82 Mon Sep 17 00:00:00 2001 From: Greg Shuflin Date: Thu, 15 Jun 2023 00:34:32 -0700 Subject: [PATCH] PR feedback --- README.md | 2 +- src/config.rs | 6 +++--- tests/unstable.rs | 31 +++++++++++++++++++++++++------ 3 files changed, 29 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 5ccb77aaf4..e1060b1ad0 100644 --- a/README.md +++ b/README.md @@ -320,7 +320,7 @@ This does not, however, preclude fixing outright bugs, even if doing so might br There will never be a `just` 2.0. Any desirable backwards-incompatible changes will be opt-in on a per-`justfile` basis, so users may migrate at their leisure. Features that aren't yet ready for stabilization are gated behind the `--unstable` flag. Features enabled by `--unstable` may change in backwards incompatible ways at any time. The unstable -mode can also be set using the environment variable `JUST_ALLOW_UNSTABLE=true` (any other value for the variable besides `true` is treated as false). +mode can also be set using the environment variable `JUST_UNSTABLE`; any value for this variable other than "false", "0", or the empty string will be treated as enabling unstable mode. Editor Support diff --git a/src/config.rs b/src/config.rs index d523fccd28..5e9f685315 100644 --- a/src/config.rs +++ b/src/config.rs @@ -3,8 +3,6 @@ use { clap::{App, AppSettings, Arg, ArgGroup, ArgMatches, ArgSettings}, }; -pub(crate) const UNSTABLE_KEY: &str = "JUST_ALLOW_UNSTABLE"; - // These three strings should be kept in sync: pub(crate) const CHOOSER_DEFAULT: &str = "fzf --multi --preview 'just --show {}'"; pub(crate) const CHOOSER_ENVIRONMENT_KEY: &str = "JUST_CHOOSER"; @@ -572,7 +570,9 @@ impl Config { }; let unstable = matches.is_present(arg::UNSTABLE) - || std::env::var_os(UNSTABLE_KEY).map_or(false, |val| val.to_string_lossy() == "true"); + || std::env::var_os("JUST_UNSTABLE").map_or(false, |val| { + !["false", "0", ""].contains(&val.to_string_lossy().as_ref()) + }); Ok(Self { check: matches.is_present(arg::CHECK), diff --git a/tests/unstable.rs b/tests/unstable.rs index 773f3c0d9f..fcea21b7b7 100644 --- a/tests/unstable.rs +++ b/tests/unstable.rs @@ -6,17 +6,37 @@ fn set_unstable_true_with_env_var() { default: echo 'foo' "#; - Test::new() + + for val in ["true", "some-arbitrary-string"] { + Test::new() + .justfile(justfile) + .args(["--dump", "--dump-format", "json"]) + .env("JUST_UNSTABLE", val) + .status(EXIT_SUCCESS) + .stdout_regex("*") + .run(); + } +} + +#[test] +fn set_unstable_false_with_env_var() { + let justfile = r#" +default: + echo 'foo' + "#; + for val in ["0", "", "false"] { + Test::new() .justfile(justfile) .args(["--dump", "--dump-format", "json"]) - .env("JUST_ALLOW_UNSTABLE", "true") - .status(EXIT_SUCCESS) - .stdout_regex("*") + .env("JUST_UNSTABLE", val) + .status(EXIT_FAILURE) + .stderr("error: The JSON dump format is currently unstable. Invoke `just` with the `--unstable` flag to enable unstable features.\n") .run(); + } } #[test] -fn set_unstable_false_with_env_var() { +fn set_unstable_false_with_env_var_unset() { let justfile = r#" default: echo 'foo' @@ -24,7 +44,6 @@ default: Test::new() .justfile(justfile) .args(["--dump", "--dump-format", "json"]) - .env("JUST_ALLOW_UNSTABLE", "false") .status(EXIT_FAILURE) .stderr("error: The JSON dump format is currently unstable. Invoke `just` with the `--unstable` flag to enable unstable features.\n") .run();