diff --git a/Cargo.toml b/Cargo.toml index fea4cd2f29..2d9c5401b7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -22,7 +22,7 @@ ansi_term = "0.12.0" atty = "0.2.0" blake3 = { version = "1.5.0", features = ["rayon", "mmap"] } camino = "1.0.4" -clap = { version = "4.0.0", features = ["wrap_help"] } +clap = { version = "4.0.0", features = ["env", "wrap_help"] } clap_complete = "4.0.0" ctrlc = { version = "3.1.1", features = ["termination"] } derivative = "2.0.0" diff --git a/src/config.rs b/src/config.rs index ec4965282b..430d1b24f8 100644 --- a/src/config.rs +++ b/src/config.rs @@ -1,16 +1,16 @@ use { super::*, clap::{ - builder::{styling::AnsiColor, PossibleValuesParser, Styles}, + builder::{styling::AnsiColor, FalseyValueParser, PossibleValuesParser, Styles}, value_parser, Arg, ArgAction, ArgGroup, ArgMatches, Command, }, }; -pub(crate) const CHOOSER_ENVIRONMENT_KEY: &str = "JUST_CHOOSER"; +const CHOOSER_ENVIRONMENT_KEY: &str = "JUST_CHOOSER"; -pub(crate) const CHOOSE_HELP: &str = "Select one or more recipes to run using a binary chooser. \ - If `--chooser` is not passed the chooser defaults to the \ - value of $JUST_CHOOSER, falling back to `fzf`"; +const CHOOSE_HELP: &str = "Select one or more recipes to run using a binary chooser. \ + If `--chooser` is not passed the chooser defaults to the \ + value of $JUST_CHOOSER, falling back to `fzf`"; pub(crate) fn chooser_default(justfile: &Path) -> OsString { let mut chooser = OsString::new(); @@ -160,6 +160,7 @@ impl Config { .arg( Arg::new(arg::CHOOSER) .long("chooser") + .env(CHOOSER_ENVIRONMENT_KEY) .action(ArgAction::Set) .help("Override binary invoked by `--choose`"), ) @@ -299,7 +300,9 @@ impl Config { .arg( Arg::new(arg::UNSTABLE) .long("unstable") + .env("JUST_UNSTABLE") .action(ArgAction::SetTrue) + .value_parser(FalseyValueParser::new()) .help("Enable unstable features"), ) .arg( @@ -654,10 +657,7 @@ impl Config { .map(|s| s.map(Into::into).collect()) }; - let unstable = matches.get_flag(arg::UNSTABLE) - || env::var_os("JUST_UNSTABLE") - .map(|val| !(val == "false" || val == "0" || val.is_empty())) - .unwrap_or_default(); + let unstable = matches.get_flag(arg::UNSTABLE); Ok(Self { check: matches.get_flag(arg::CHECK), diff --git a/src/subcommand.rs b/src/subcommand.rs index 12293ade67..3d54eb30db 100644 --- a/src/subcommand.rs +++ b/src/subcommand.rs @@ -217,10 +217,7 @@ impl Subcommand { return Err(Error::NoChoosableRecipes); } - let chooser = chooser - .map(OsString::from) - .or_else(|| env::var_os(config::CHOOSER_ENVIRONMENT_KEY)) - .unwrap_or_else(|| config::chooser_default(&search.justfile)); + let chooser = chooser.map_or_else(|| config::chooser_default(&search.justfile), From::from); let result = justfile .settings