forked from vercel/turborepo
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: Port logout to be pure Rust (vercel#3302)
With this PR `turbo logout` can run without jumping to Go. Notes: - Used `config-rs` for our config reading. It doesn't support writing configs to disk out of the box, but this can be solved with a wrapper struct. This can probably be abstracted to be generic over different configs, but we should hold off until that seems beneficial. - `termcolor` is used for coloring output, this is the same crate that `env_logger` uses for coloring outputs. The `UI` struct is expected to be passed into any subcommands that need pretty output. - A slight behavior change is that we no longer delete the entire config file and instead make the token null (`"token": null`). If this is unwanted, I can change it back to the old behavior, but I wanted to test out `UserConfig::set_token` before someone else tried using it. Co-authored-by: Leah <[email protected]>
- Loading branch information
1 parent
99ad481
commit cda0322
Showing
10 changed files
with
338 additions
and
29 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
use anyhow::Result; | ||
use log::error; | ||
|
||
use crate::{ | ||
config::{default_user_config_path, UserConfig}, | ||
ui::{GREY, UI}, | ||
}; | ||
|
||
pub fn logout(ui: UI) -> Result<()> { | ||
let mut config = UserConfig::load(&default_user_config_path()?, None)?; | ||
|
||
if let Err(err) = config.set_token(None) { | ||
error!("could not logout. Something went wrong: {}", err); | ||
return Err(err); | ||
} | ||
|
||
println!("{}", ui.apply(GREY.apply_to(">>> Logged out"))); | ||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
pub(crate) mod bin; | ||
pub(crate) mod logout; |
Oops, something went wrong.