mirror of
https://github.com/aramperes/nut-rs.git
synced 2025-09-09 13:38:30 -04:00
parent
f22867d2d2
commit
3002b4de53
11 changed files with 171 additions and 75 deletions
|
@ -41,15 +41,23 @@ fn main() -> anyhow::Result<()> {
|
|||
.arg(
|
||||
Arg::with_name("debug")
|
||||
.short("D")
|
||||
.long("debug")
|
||||
.takes_value(false)
|
||||
.help("Enables debug mode (logs network commands to stderr)."),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("ssl")
|
||||
.short("S")
|
||||
.long("ssl")
|
||||
.takes_value(false)
|
||||
.help("Enables SSL on the connection with upsd."),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("insecure-ssl")
|
||||
.long("insecure-ssl")
|
||||
.takes_value(false)
|
||||
.help("Disables SSL verification on the connection with upsd."),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("upsd-server")
|
||||
.required(false)
|
||||
|
@ -70,13 +78,15 @@ fn main() -> anyhow::Result<()> {
|
|||
)?;
|
||||
|
||||
let debug = args.is_present("debug");
|
||||
let ssl = args.is_present("ssl");
|
||||
let insecure_ssl = args.is_present("insecure-ssl");
|
||||
let ssl = insecure_ssl || args.is_present("ssl");
|
||||
|
||||
let host = server.try_into()?;
|
||||
let config = nut_client::ConfigBuilder::new()
|
||||
.with_host(host)
|
||||
.with_debug(debug)
|
||||
.with_ssl(ssl)
|
||||
.with_insecure_ssl(insecure_ssl)
|
||||
.build();
|
||||
|
||||
if args.is_present("list") {
|
||||
|
|
|
@ -1,9 +1,8 @@
|
|||
use anyhow::Context;
|
||||
use std::convert::{TryFrom, TryInto};
|
||||
use std::fmt;
|
||||
use std::net::ToSocketAddrs;
|
||||
|
||||
pub const DEFAULT_HOSTNAME: &str = "127.0.0.1";
|
||||
pub const DEFAULT_HOSTNAME: &str = "localhost";
|
||||
pub const DEFAULT_PORT: u16 = 3493;
|
||||
|
||||
/// Connection information for a upsd server.
|
||||
|
@ -69,12 +68,9 @@ impl<'a> TryInto<nut_client::Host> for UpsdName<'a> {
|
|||
type Error = anyhow::Error;
|
||||
|
||||
fn try_into(self) -> anyhow::Result<nut_client::Host> {
|
||||
Ok((String::from(self.hostname), self.port)
|
||||
.to_socket_addrs()
|
||||
.with_context(|| "Failed to convert to SocketAddr")?
|
||||
.next()
|
||||
.with_context(|| "Failed to convert to SocketAddr")?
|
||||
.into())
|
||||
(self.hostname.to_owned(), self.port)
|
||||
.try_into()
|
||||
.with_context(|| "Invalid hostname/port")
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -131,7 +127,7 @@ mod tests {
|
|||
port: DEFAULT_PORT
|
||||
}
|
||||
);
|
||||
assert_eq!(format!("{}", name), "ups0@127.0.0.1:3493");
|
||||
assert_eq!(format!("{}", name), "ups0@localhost:3493");
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue