1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
//! The `accounts` subcommand: report what each configured account can do.
//!
//! Split from `main.rs` to keep that file within the repository's 1000-line
//! limit.
use std::process::ExitCode;
use link_assistant_router::accounts::AccountRouter;
use link_assistant_router::cli::AccountOp;
/// Render the account pool.
///
/// `credential` is printed beside `healthy` so an operator can see *why* an
/// account is unhealthy without running `doctor`, which was the contradiction
/// issue #242 reported: `accounts list` said `healthy true` while `doctor`
/// said EXPIRED and every request returned 401.
pub fn run(
router: &AccountRouter,
refreshes: Option<&link_assistant_router::refresh::TokenCache>,
op: &AccountOp,
) -> ExitCode {
match op {
AccountOp::List => {
println!(
"{:<16} {:<8} {:<12} {:<6} {:<9} {:<9} home",
"name", "healthy", "credential", "used", "limit", "remaining"
);
for h in router.health_snapshot_with(refreshes) {
let limit = h
.request_limit
.map_or_else(|| "-".to_string(), |value| value.to_string());
let remaining = h
.remaining_requests
.map_or_else(|| "-".to_string(), |value| value.to_string());
println!(
"{:<16} {:<8} {:<12} {:<6} {:<9} {:<9} {}",
h.name,
h.healthy,
h.credential,
h.used,
limit,
remaining,
h.home.display()
);
}
ExitCode::SUCCESS
}
}
}