From 4aab92147c56b8b418cbb5423a2ffd771f92eb6e Mon Sep 17 00:00:00 2001 From: Greg Shuflin Date: Thu, 20 Apr 2023 23:32:45 -0700 Subject: [PATCH 1/9] Allow --unstable to be set with an environment variable Allow the environment variable JUST_ALLOW_UNSTABLE=true to act as equivalent to the --unstable flag. Any other value of JUST_ALLOW_UNSTABLE is treated as false. --- README.md | 4 +++- src/config.rs | 7 ++++++- tests/lib.rs | 1 + tests/test.rs | 2 +- tests/unstable.rs | 31 +++++++++++++++++++++++++++++++ 5 files changed, 42 insertions(+), 3 deletions(-) create mode 100644 tests/unstable.rs diff --git a/README.md b/README.md index aaa94fb04e..5ccb77aaf4 100644 --- a/README.md +++ b/README.md @@ -319,7 +319,9 @@ 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. +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). + Editor Support -------------- diff --git a/src/config.rs b/src/config.rs index 70cb43fa2a..d523fccd28 100644 --- a/src/config.rs +++ b/src/config.rs @@ -3,6 +3,8 @@ 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"; @@ -569,6 +571,9 @@ impl Config { None }; + let unstable = matches.is_present(arg::UNSTABLE) + || std::env::var_os(UNSTABLE_KEY).map_or(false, |val| val.to_string_lossy() == "true"); + Ok(Self { check: matches.is_present(arg::CHECK), dry_run: matches.is_present(arg::DRY_RUN), @@ -578,7 +583,7 @@ impl Config { load_dotenv: !matches.is_present(arg::NO_DOTENV), shell_command: matches.is_present(arg::SHELL_COMMAND), unsorted: matches.is_present(arg::UNSORTED), - unstable: matches.is_present(arg::UNSTABLE), + unstable, list_heading: matches .value_of(arg::LIST_HEADING) .unwrap_or("Available recipes:\n") diff --git a/tests/lib.rs b/tests/lib.rs index 23f5a720ac..e49303fc8c 100644 --- a/tests/lib.rs +++ b/tests/lib.rs @@ -86,6 +86,7 @@ mod string; mod subsequents; mod tempdir; mod undefined_variables; +mod unstable; #[cfg(target_family = "windows")] mod windows_shell; mod working_directory; diff --git a/tests/test.rs b/tests/test.rs index 6c86f0ae1b..e8dc786bb7 100644 --- a/tests/test.rs +++ b/tests/test.rs @@ -234,7 +234,7 @@ impl Test { if let Some(ref stdout_regex) = self.stdout_regex { if !stdout_regex.is_match(output_stdout) { - panic!("Stdout regex mismatch:\n{output_stderr:?}\n!~=\n/{stdout_regex:?}/"); + panic!("Stdout regex mismatch:\n{output_stdout:?}\n!~=\n/{stdout_regex:?}/"); } } diff --git a/tests/unstable.rs b/tests/unstable.rs new file mode 100644 index 0000000000..773f3c0d9f --- /dev/null +++ b/tests/unstable.rs @@ -0,0 +1,31 @@ +use super::*; + +#[test] +fn set_unstable_true_with_env_var() { + let justfile = r#" +default: + echo 'foo' + "#; + Test::new() + .justfile(justfile) + .args(["--dump", "--dump-format", "json"]) + .env("JUST_ALLOW_UNSTABLE", "true") + .status(EXIT_SUCCESS) + .stdout_regex("*") + .run(); +} + +#[test] +fn set_unstable_false_with_env_var() { + let justfile = r#" +default: + echo 'foo' + "#; + 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(); +} From d916d0ee06efe915a4e9e81701e7a68e4f12f28e Mon Sep 17 00:00:00 2001 From: Greg Shuflin Date: Fri, 21 Apr 2023 00:01:15 -0700 Subject: [PATCH 2/9] Add clippy lint override --- src/thunk.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/thunk.rs b/src/thunk.rs index 353e3c90ea..638c87724b 100644 --- a/src/thunk.rs +++ b/src/thunk.rs @@ -1,3 +1,4 @@ +#![allow(clippy::let_underscore_untyped)] use super::*; #[derive(Derivative)] From 5e395dbdfe3e78b691c87737a074a84f8b203b82 Mon Sep 17 00:00:00 2001 From: Greg Shuflin Date: Thu, 15 Jun 2023 00:34:32 -0700 Subject: [PATCH 3/9] 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(); From 974acd56554d0d8186c464cf330833ddeda396f8 Mon Sep 17 00:00:00 2001 From: Casey Rodarmor Date: Sun, 8 Oct 2023 20:33:13 -0700 Subject: [PATCH 4/9] Use --fmt command since --dump-format json is stable --- tests/unstable.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/unstable.rs b/tests/unstable.rs index fcea21b7b7..23a5fa6ede 100644 --- a/tests/unstable.rs +++ b/tests/unstable.rs @@ -10,10 +10,10 @@ default: for val in ["true", "some-arbitrary-string"] { Test::new() .justfile(justfile) - .args(["--dump", "--dump-format", "json"]) + .args(["--fmt"]) .env("JUST_UNSTABLE", val) .status(EXIT_SUCCESS) - .stdout_regex("*") + .stderr_regex("Wrote justfile to `.*`\n") .run(); } } @@ -27,10 +27,10 @@ default: for val in ["0", "", "false"] { Test::new() .justfile(justfile) - .args(["--dump", "--dump-format", "json"]) + .args(["--fmt"]) .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") + .stderr("error: The `--fmt` command is currently unstable. Invoke `just` with the `--unstable` flag to enable unstable features.\n") .run(); } } @@ -43,8 +43,8 @@ default: "#; Test::new() .justfile(justfile) - .args(["--dump", "--dump-format", "json"]) + .args(["--fmt"]) .status(EXIT_FAILURE) - .stderr("error: The JSON dump format is currently unstable. Invoke `just` with the `--unstable` flag to enable unstable features.\n") + .stderr("error: The `--fmt` command is currently unstable. Invoke `just` with the `--unstable` flag to enable unstable features.\n") .run(); } From 8e919a7b170f3c3fc27130378d3223f328e2dc30 Mon Sep 17 00:00:00 2001 From: Casey Rodarmor Date: Sun, 8 Oct 2023 20:37:15 -0700 Subject: [PATCH 5/9] Reword readme --- README.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/README.md b/README.md index 4965d1f1a5..e586e2253f 100644 --- a/README.md +++ b/README.md @@ -325,8 +325,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_UNSTABLE`; any value for this variable other than "false", "0", or the empty string will be treated as enabling unstable mode. +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. Unstable features also be enabled by setting the environment variable `JUST_UNSTABLE` to any value other than `false`, `0`, or the empty string. Editor Support From f674c6fac054ce0196d1f3b0032819e0a581b441 Mon Sep 17 00:00:00 2001 From: Casey Rodarmor Date: Sun, 8 Oct 2023 20:38:11 -0700 Subject: [PATCH 6/9] Tweak --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index e586e2253f..928c59faac 100644 --- a/README.md +++ b/README.md @@ -325,7 +325,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. Unstable features also be enabled by setting the environment variable `JUST_UNSTABLE` to any value other than `false`, `0`, or the empty string. +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. Unstable features can also be enabled by setting the environment variable `JUST_UNSTABLE` to any value other than `false`, `0`, or the empty string. Editor Support From bb17415695d5b9ca7add574d276688675b766598 Mon Sep 17 00:00:00 2001 From: Casey Rodarmor Date: Sun, 8 Oct 2023 20:39:03 -0700 Subject: [PATCH 7/9] Use unwrap_or_default --- src/config.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/config.rs b/src/config.rs index 5e9f685315..5377709b6d 100644 --- a/src/config.rs +++ b/src/config.rs @@ -570,9 +570,9 @@ impl Config { }; let unstable = matches.is_present(arg::UNSTABLE) - || std::env::var_os("JUST_UNSTABLE").map_or(false, |val| { - !["false", "0", ""].contains(&val.to_string_lossy().as_ref()) - }); + || std::env::var_os("JUST_UNSTABLE") + .map(|val| !["false", "0", ""].contains(&val.to_string_lossy().as_ref())) + .unwrap_or_default(); Ok(Self { check: matches.is_present(arg::CHECK), From 8fbeee3baf72e402621015490994be2c4f0854c8 Mon Sep 17 00:00:00 2001 From: Casey Rodarmor Date: Sun, 8 Oct 2023 20:44:10 -0700 Subject: [PATCH 8/9] Tweak --- src/config.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/config.rs b/src/config.rs index 5377709b6d..14904c5bad 100644 --- a/src/config.rs +++ b/src/config.rs @@ -571,7 +571,7 @@ impl Config { let unstable = matches.is_present(arg::UNSTABLE) || std::env::var_os("JUST_UNSTABLE") - .map(|val| !["false", "0", ""].contains(&val.to_string_lossy().as_ref())) + .map(|val| !(val == "false" || val == "0" || val.is_empty())) .unwrap_or_default(); Ok(Self { From f794ac093ecfad0f202a15180ed87106f36ba456 Mon Sep 17 00:00:00 2001 From: Casey Rodarmor Date: Sun, 8 Oct 2023 20:44:52 -0700 Subject: [PATCH 9/9] Remove clippy allow --- src/thunk.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/thunk.rs b/src/thunk.rs index 638c87724b..353e3c90ea 100644 --- a/src/thunk.rs +++ b/src/thunk.rs @@ -1,4 +1,3 @@ -#![allow(clippy::let_underscore_untyped)] use super::*; #[derive(Derivative)]