Skip to content
This repository was archived by the owner on Sep 1, 2023. It is now read-only.

Commit 4f54014

Browse files
committed
feat: add loading spinner
1 parent 638a02e commit 4f54014

File tree

5 files changed

+64
-10
lines changed

5 files changed

+64
-10
lines changed

Cargo.lock

Lines changed: 46 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@ colored = "2.0.0"
1111
directories = "4.0.1"
1212
reqwest = { version = "0.11.11", features = ["blocking", "json"] }
1313
sentry = "0.27.0"
14+
spinners = "4.1.0"

src/commands/authstatus.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@ pub fn authstatus() -> std::io::Result<()> {
1010
stars.push('*');
1111
}
1212
println!("{} Token: {}{}", "✔".green(), &token[..5], stars);
13-
if !auth::validate_token() {
14-
eprintln!("{} {}", "WARN:".yellow().bold(), "Your token is invalid!".yellow())
15-
}
13+
super::check_token();
1614
}
1715
Err(err) => match err.kind() {
1816
ErrorKind::NotFound => {

src/commands/login.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
11
use clap::*;
22
use colored::Colorize;
3-
use crate::auth;
43
pub fn login(matches: &ArgMatches) -> std::io::Result<()>{
54
let token = matches.get_one::<String>("token").unwrap().clone();
65
if let Err(err) = crate::auth::login(token) {
7-
eprintln!("{}{}{}", "Couldn't save the token: ".red(), err.kind().to_string().red(), "✘".red());
6+
eprintln!("{} Couldn't save the token: {}", "✘".red(), err.kind().to_string());
87
Err(err)
98
} else {
10-
println!("{}", "Token saved successfully ✔".green());
11-
if !auth::validate_token() {
12-
eprintln!("{} {}", "WARN:".yellow().bold(), "Your token is invalid!".yellow())
13-
}
9+
println!("{} Token saved successfully", "✔".green());
10+
super::check_token();
1411
Ok(())
1512
}
1613
}

src/commands/mod.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,14 @@
11
pub mod login;
2-
pub mod authstatus;
2+
pub mod authstatus;
3+
use spinners::*;
4+
use colored::Colorize;
5+
pub fn check_token() {
6+
let mut validate_spinner = Spinner::new(Spinners::Dots12, "Checking token".into());
7+
validate_spinner.stop_with_message(
8+
if crate::auth::validate_token() {
9+
format!("{} {}", "✔".green().bold(), "Your token is valid!")
10+
} else {
11+
format!("{} {}", "!".yellow().bold(), "Your token is invalid!")
12+
}
13+
);
14+
}

0 commit comments

Comments
 (0)