mirror of
https://github.com/arampoire/nut-rs.git
synced 2025-12-01 00:30:23 -05:00
rupsc: Implement listing clients
This commit is contained in:
parent
52afe6bbd1
commit
abd38f0a99
4 changed files with 66 additions and 1 deletions
|
|
@ -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()
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue