mirror of
https://github.com/aramperes/nut-rs.git
synced 2025-09-08 05:08:31 -04:00
parent
f3814c831d
commit
b6e3a96aa1
3 changed files with 48 additions and 2 deletions
|
@ -45,7 +45,8 @@ async fn main() -> nut_client::Result<()> {
|
|||
// List UPS commands
|
||||
println!("\t Commands:");
|
||||
for cmd in conn.list_commands(&name).await? {
|
||||
println!("\t\t- {}", cmd);
|
||||
let description = conn.get_command_description(&name, &cmd).await?;
|
||||
println!("\t\t- {} ({})", cmd, description);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -44,7 +44,8 @@ fn main() -> nut_client::Result<()> {
|
|||
// List UPS commands
|
||||
println!("\t Commands:");
|
||||
for cmd in conn.list_commands(&name)? {
|
||||
println!("\t\t- {}", cmd);
|
||||
let description = conn.get_command_description(&name, &cmd)?;
|
||||
println!("\t\t- {} ({})", cmd, description);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -80,6 +80,10 @@ pub enum Response {
|
|||
///
|
||||
/// Params: (command name)
|
||||
Cmd(String),
|
||||
/// A command description (CMDDESC) response.
|
||||
///
|
||||
/// Params: (command description)
|
||||
CmdDesc(String),
|
||||
}
|
||||
|
||||
impl Response {
|
||||
|
@ -217,6 +221,30 @@ impl Response {
|
|||
}?;
|
||||
Ok(Response::Cmd(name))
|
||||
}
|
||||
"CMDDESC" => {
|
||||
let _device = if args.is_empty() {
|
||||
Err(ClientError::from(NutError::Generic(
|
||||
"Unspecified CMDDESC device in response".into(),
|
||||
)))
|
||||
} else {
|
||||
Ok(args.remove(0))
|
||||
}?;
|
||||
let _name = if args.is_empty() {
|
||||
Err(ClientError::from(NutError::Generic(
|
||||
"Unspecified CMDDESC name in response".into(),
|
||||
)))
|
||||
} else {
|
||||
Ok(args.remove(0))
|
||||
}?;
|
||||
let desc = if args.is_empty() {
|
||||
Err(ClientError::from(NutError::Generic(
|
||||
"Unspecified CMDDESC description in response".into(),
|
||||
)))
|
||||
} else {
|
||||
Ok(args.remove(0))
|
||||
}?;
|
||||
Ok(Response::CmdDesc(desc))
|
||||
}
|
||||
_ => Err(NutError::UnknownResponseType(cmd_name).into()),
|
||||
}
|
||||
}
|
||||
|
@ -272,6 +300,14 @@ impl Response {
|
|||
Err(NutError::UnexpectedResponse.into())
|
||||
}
|
||||
}
|
||||
|
||||
pub fn expect_cmddesc(&self) -> crate::Result<String> {
|
||||
if let Self::CmdDesc(description) = &self {
|
||||
Ok(description.to_owned())
|
||||
} else {
|
||||
Err(NutError::UnexpectedResponse.into())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// A macro for implementing `LIST` commands.
|
||||
|
@ -513,6 +549,14 @@ implement_get_commands! {
|
|||
{ |row: Response| row.expect_var() },
|
||||
)
|
||||
}
|
||||
|
||||
/// Queries the description of a UPS command.
|
||||
pub fn get_command_description(ups_name: &str, variable: &str) -> String {
|
||||
(
|
||||
{ &["CMDDESC", ups_name, variable] },
|
||||
{ |row: Response| row.expect_cmddesc() },
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
implement_simple_commands! {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue