diff --git a/README.md b/README.md index c2760a9ace..096407ff93 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 069a9a8d20..8cb0c40a65 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 --preview 'just --show {}'"; pub(crate) const CHOOSER_ENVIRONMENT_KEY: &str = "JUST_CHOOSER"; @@ -568,6 +570,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), @@ -577,7 +582,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 dabb520c53..854c270512 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(); +}