diff --git a/crates/turborepo-auth/src/auth/logout.rs b/crates/turborepo-auth/src/auth/logout.rs index 2f3d7cacf94de..80a838065dca3 100644 --- a/crates/turborepo-auth/src/auth/logout.rs +++ b/crates/turborepo-auth/src/auth/logout.rs @@ -1,16 +1,5 @@ -use anyhow::Result; -use tracing::error; -use turborepo_ui::{GREY, UI}; +use turborepo_ui::{cprintln, GREY, UI}; -pub fn logout(ui: &UI, mut set_token: F) -> Result<()> -where - F: FnMut() -> Result<()>, -{ - if let Err(err) = set_token() { - error!("could not logout. Something went wrong: {}", err); - return Err(err); - } - - println!("{}", ui.apply(GREY.apply_to(">>> Logged out"))); - Ok(()) +pub fn logout(ui: &UI) { + cprintln!(ui, GREY, ">>> Logged out"); } diff --git a/crates/turborepo-lib/src/commands/logout.rs b/crates/turborepo-lib/src/commands/logout.rs index 82415b9e94107..cb4eed6fa2b9c 100644 --- a/crates/turborepo-lib/src/commands/logout.rs +++ b/crates/turborepo-lib/src/commands/logout.rs @@ -1,33 +1,37 @@ use anyhow::{anyhow, Error, Result}; +use tracing::error; use turborepo_auth::logout as auth_logout; use crate::{commands::CommandBase, rewrite_json::unset_path}; pub fn logout(base: &mut CommandBase) -> Result<()> { - let ui = base.ui; + if let Err(err) = remove_token(base) { + error!("could not logout. Something went wrong: {}", err); + return Err(err); + } - // Passing a closure here while we figure out how to make turborepo-auth - // crate manage its own configuration for the path to the token. - let set_token = || -> Result<(), Error> { - let global_config_path = base.global_config_path()?; - let before = global_config_path - .read_existing_to_string_or(Ok("{}")) - .map_err(|e| { - anyhow!( - "Encountered an IO error while attempting to read {}: {}", - global_config_path, - e - ) - })?; + auth_logout(&base.ui); - if let Some(after) = unset_path(&before, &["token"], true)? { - global_config_path - .create_with_contents(after) - .map_err(Error::from) - } else { - Ok(()) - } - }; + Ok(()) +} + +fn remove_token(base: &mut CommandBase) -> Result<()> { + let global_config_path = base.global_config_path()?; + let before = global_config_path + .read_existing_to_string_or(Ok("{}")) + .map_err(|e| { + anyhow!( + "Encountered an IO error while attempting to read {}: {}", + global_config_path, + e + ) + })?; - auth_logout(&ui, set_token) + if let Some(after) = unset_path(&before, &["token"], true)? { + global_config_path + .create_with_contents(after) + .map_err(Error::from) + } else { + Ok(()) + } }