File tree Expand file tree Collapse file tree 1 file changed +16
-7
lines changed Expand file tree Collapse file tree 1 file changed +16
-7
lines changed Original file line number Diff line number Diff line change 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
-
5
1
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
+ }
7
15
8
16
fn main ( ) -> AppResult < ( ) > {
17
+ let opts: Opts = Opts :: parse ( ) ;
18
+
9
19
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 ) ?;
12
21
println ! ( "The token belongs to user {}" , user. gh_login) ;
13
22
Ok ( ( ) )
14
23
}
You can’t perform that action at this time.
0 commit comments