23 lines
723 B
Rust
23 lines
723 B
Rust
use crate::auth::AuthedClient;
|
|
use crate::ui;
|
|
use anyhow::{anyhow, Result};
|
|
use rsh_types::{ConnectionView, OpReq, OpResp};
|
|
|
|
pub async fn list(client: &AuthedClient, session: Option<String>) -> Result<()> {
|
|
let conns = fetch(client, session).await?;
|
|
if conns.is_empty() {
|
|
ui::print_info("no connections");
|
|
} else {
|
|
println!("{}", ui::connections_table(&conns));
|
|
}
|
|
Ok(())
|
|
}
|
|
|
|
pub async fn fetch(client: &AuthedClient, session: Option<String>) -> Result<Vec<ConnectionView>> {
|
|
match client.req(OpReq::ConnectionList { session }).await? {
|
|
OpResp::Connections(c) => Ok(c),
|
|
OpResp::Err(e) => Err(anyhow!(e)),
|
|
other => Err(anyhow!("unexpected: {other:?}")),
|
|
}
|
|
}
|