change map_or_else to unwrap_or_else

This commit is contained in:
Darren Schroeder 2024-06-19 16:12:11 -05:00
parent e1c482ddb9
commit 95c1fbd9b8

View File

@ -194,29 +194,31 @@ pub(crate) fn create_nu_constant(engine_state: &EngineState, span: Span) -> Valu
// if not, use the default /usr/share/nushell/vendor/autoload // if not, use the default /usr/share/nushell/vendor/autoload
// check to see if NU_VENDOR_AUTOLOAD_DIR env var is set, if not, use the default // check to see if NU_VENDOR_AUTOLOAD_DIR env var is set, if not, use the default
option_env!("NU_VENDOR_AUTOLOAD_DIR") Value::string(
.map(String::from) option_env!("NU_VENDOR_AUTOLOAD_DIR")
.or_else(|| { .map(String::from)
if cfg!(windows) { .unwrap_or_else(|| {
let all_user_profile = match engine_state.get_env_var("ALLUSERPROFILE") { if cfg!(windows) {
Some(v) => format!( let all_user_profile = match engine_state.get_env_var("ALLUSERPROFILE") {
"{}\\nushell\\vendor\\autoload", Some(v) => format!(
v.coerce_string().unwrap_or("C:\\ProgramData".into()) "{}\\nushell\\vendor\\autoload",
), v.coerce_string().unwrap_or("C:\\ProgramData".into())
None => "C:\\ProgramData\\nushell\\vendor\\autoload".into(), ),
}; None => "C:\\ProgramData\\nushell\\vendor\\autoload".into(),
Some(all_user_profile) };
} else { all_user_profile
// In non-Windows environments, if NU_VENDOR_AUTOLOAD_DIR is not set } else {
// check to see if PREFIX env var is set, and use it as PREFIX/nushell/vendor/autoload // In non-Windows environments, if NU_VENDOR_AUTOLOAD_DIR is not set
// otherwise default to /usr/share/nushell/vendor/autoload // check to see if PREFIX env var is set, and use it as PREFIX/nushell/vendor/autoload
option_env!("PREFIX").map(String::from).map_or_else( // otherwise default to /usr/share/nushell/vendor/autoload
|| Some("/usr/local/share/nushell/vendor/autoload".into()), option_env!("PREFIX").map(String::from).map_or_else(
|prefix| Some(format!("{}/share/nushell/vendor/autoload", prefix)), || "/usr/local/share/nushell/vendor/autoload".into(),
) |prefix| format!("{}/share/nushell/vendor/autoload", prefix),
} )
}) }
.map_or_else(|| Value::nothing(span), |s| Value::string(s, span)), }),
span,
),
); );
record.push("temp-path", { record.push("temp-path", {