MCPcopy Create free account
hub / github.com/BigBoot/AutoKuma / handle

Function handle

kuma-cli/src/login.rs:23–64  ·  view source on GitHub ↗
(command: &Command, config: &Config, cli: &Cli)

Source from the content-addressed store, hash-verified

21}
22
23pub(crate) async fn handle(command: &Command, config: &Config, cli: &Cli) {
24 if command.clear {
25 utils::clear_auth_token().await;
26 print_value(&json!({"ok": true, "message" : "auth token cleared"}), cli);
27 return;
28 }
29
30 if command.username.is_none() {
31 Cli::command()
32 .error(
33 clap::error::ErrorKind::MissingRequiredArgument,
34 "the following required arguments were not provided:\n \x1b[32m<USERNAME|--clear>\x1b[0m",
35 )
36 .exit();
37 }
38
39 let username = command.username.clone().unwrap();
40 let password = command
41 .password
42 .clone()
43 .unwrap_or_else(|| rpassword::prompt_password("Password: ").unwrap());
44
45 let config = Config {
46 username: Some(username),
47 password: Some(password),
48 auth_token: None,
49 ..config.clone()
50 };
51
52 let client = utils::connect(&config, cli).await;
53
54 let auth_token = client.get_auth_token().await;
55
56 if let Some(token) = auth_token {
57 print_value(
58 &json!({"ok": true, "message" : "login ok", "token": token}),
59 cli,
60 );
61 } else {
62 print_value(&json!({"error" : "no auth token received"}), cli);
63 }
64}

Callers

nothing calls this directly

Calls 4

clear_auth_tokenFunction · 0.85
print_valueFunction · 0.85
connectFunction · 0.85
get_auth_tokenMethod · 0.80

Tested by

no test coverage detected