rupsc: Implement listing clients

This commit is contained in:
Aram 🍐 2021-07-31 03:44:45 -04:00
parent 52afe6bbd1
commit abd38f0a99
4 changed files with 66 additions and 1 deletions

View file

@ -43,6 +43,19 @@ pub fn list_variables(server: UpsdName, debug: bool) -> anyhow::Result<()> {
Ok(())
}
pub fn list_clients(server: UpsdName, debug: bool) -> anyhow::Result<()> {
let ups_name = server
.upsname
.with_context(|| "ups name must be specified: <upsname>[@<hostname>[:<port>]]")?;
let mut conn = connect(server, debug)?;
for client_ip in conn.list_clients(ups_name)? {
println!("{}", client_ip);
}
Ok(())
}
fn connect(server: UpsdName, debug: bool) -> anyhow::Result<Connection> {
let host = server.try_into()?;
let config = nut_client::ConfigBuilder::new()

View file

@ -73,7 +73,7 @@ fn main() -> anyhow::Result<()> {
}
if args.is_present("clients") {
todo!("listing clients")
return cmd::list_clients(server, debug);
}
// Fallback: prints one variable (or all of them)