(ctx: Context)
| 93 | } |
| 94 | |
| 95 | async fn login(ctx: Context) -> anyhow::Result<()> { |
| 96 | println!("Enter your api token:"); |
| 97 | |
| 98 | let stdin = std::io::stdin(); |
| 99 | let mut s = String::new(); |
| 100 | let _ = stdin.read_line(&mut s)?; |
| 101 | |
| 102 | let mut new_config = ctx.config; |
| 103 | new_config.api_token = s.trim().to_owned(); |
| 104 | |
| 105 | // try the token |
| 106 | let new_client = new_config.api_client(); |
| 107 | let self_user = new_client.get_self_user().await?; |
| 108 | |
| 109 | println!( |
| 110 | "Logged in as {}#{}!", |
| 111 | self_user.name, |
| 112 | self_user.discriminator() |
| 113 | ); |
| 114 | |
| 115 | confy::store(APP_NAME, &new_config)?; |
| 116 | |
| 117 | Ok(()) |
| 118 | } |
| 119 | |
| 120 | async fn check_login(ctx: Context) -> anyhow::Result<()> { |
| 121 | if ctx.config.api_token.is_empty() { |
no test coverage detected