create set_env_var function to reduce some of the copy/pasting
@@ -21,36 +21,47 @@ const STUDIO_CMD: &str = "hab-studio";
const STUDIO_CMD_ENVVAR: &str = "HAB_STUDIO_BINARY";
const STUDIO_PACKAGE_IDENT: &str = "core/hab-studio";
+// fn set_env_var(env_var: &str) -> Result<()> {
+// let config = config::load()?;
+// if henv::var(env_var).is_err() {
+// if let Some(config_val) = match env_var {
+// AUTH_TOKEN_ENVVAR => config.auth_token,
+// _ => println!("uh oh, this shouldn't happen"),
+// };
+// println!("config var is: {}", config_val);
+// env::set_var(env_var, config_val)
+// }
+// }
+
+fn set_env_var(env_var: &str, val: String) -> Result<()> {
+ debug!("Setting {}={} via config file", env_var, &val);
+ env::set_var(env_var, val);
+ Ok(())
+}
+
pub fn start(ui: &mut UI, args: &[OsString]) -> Result<()> {
- if henv::var(AUTH_TOKEN_ENVVAR).is_err() {
let config = config::load()?;
+ if henv::var(AUTH_TOKEN_ENVVAR).is_err() {
if let Some(auth_token) = config.auth_token {
- debug!("Setting {}={} via config file", AUTH_TOKEN_ENVVAR, &auth_token);
- env::set_var("HAB_AUTH_TOKEN", auth_token);
+ set_env_var(AUTH_TOKEN_ENVVAR, auth_token)?;
}
}
if henv::var(BLDR_URL_ENVVAR).is_err() {
- let config = config::load()?;
if let Some(bldr_url) = config.bldr_url {
- debug!("Setting {}={} via config file", BLDR_URL_ENVVAR, &bldr_url);
- env::set_var("HAB_BLDR_URL", bldr_url);
+ set_env_var(BLDR_URL_ENVVAR, bldr_url)?;
}
}
if henv::var(CTL_SECRET_ENVVAR).is_err() {
- let config = config::load()?;
if let Some(ctl_secret) = config.ctl_secret {
- debug!("Setting {}={} via config file", CTL_SECRET_ENVVAR, &ctl_secret);
- env::set_var("CTL_SECRET_ENVVAR", ctl_secret);
+ set_env_var(CTL_SECRET_ENVVAR, ctl_secret)?;
}
}
if henv::var(ORIGIN_ENVVAR).is_err() {
- let config = config::load()?;
if let Some(default_origin) = config.origin {
- debug!("Setting default origin {} via CLI config", &default_origin);
- env::set_var("HAB_ORIGIN", default_origin);
+ set_env_var(ORIGIN_ENVVAR, default_origin)?;
}
}
