Skip to content

Commit 336305e

Browse files
committed
bin/verify-token: Use clap for CLI argument parsing
1 parent 1e1cf4d commit 336305e

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

src/bin/verify-token.rs

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,23 @@
1-
// Look up a username by API token. Used by staff to verify someone's identity
2-
// by having an API token given. If an error occurs, including being unable to
3-
// find a user with that API token, the error will be displayed.
4-
51
use cargo_registry::{db, models::User, util::errors::AppResult};
6-
use std::env;
2+
3+
use clap::Clap;
4+
5+
#[derive(Clap, Debug)]
6+
#[clap(
7+
name = "verify-token",
8+
about = "Look up a username by API token. Used by staff to verify someone's identity \
9+
by having an API token given. If an error occurs, including being unable to \
10+
find a user with that API token, the error will be displayed."
11+
)]
12+
struct Opts {
13+
api_token: String,
14+
}
715

816
fn main() -> AppResult<()> {
17+
let opts: Opts = Opts::parse();
18+
919
let conn = db::connect_now()?;
10-
let token = env::args().nth(1).expect("API token argument required");
11-
let user = User::find_by_api_token(&conn, &token)?;
20+
let user = User::find_by_api_token(&conn, &opts.api_token)?;
1221
println!("The token belongs to user {}", user.gh_login);
1322
Ok(())
1423
}

0 commit comments

Comments
 (0)