initial commit
This commit is contained in:
22
crates/rshc/src/cmd/connection.rs
Normal file
22
crates/rshc/src/cmd/connection.rs
Normal file
@@ -0,0 +1,22 @@
|
||||
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:?}")),
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user