4e73766732
Cache parsed auth state per remote and validate it with on-disk file metadata so repeated authenticated API calls can skip redundant open/read/JSON parse work within one process. Centralize cache load, persist, and removal helpers in the cache module, reuse them from login, logout, and whoami, and update the refresh path to persist structured cache data directly. Add targeted cache tests for memory reuse, invalidation after external writes, persist updates, and cache removal. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
11 lines
325 B
Rust
11 lines
325 B
Rust
pub async fn whoami(remote: &str) -> Result<(), anyhow::Error> {
|
|
match crate::cache::load_cache(remote) {
|
|
Ok(cache) => match cache.user {
|
|
Some(user) => println!("{}", user.username),
|
|
None => println!("(Anonymous)"),
|
|
},
|
|
Err(_) => println!("(Anonymous)"),
|
|
}
|
|
Ok(())
|
|
}
|