use Results and not unwraps (#10)

* use `Result`s and not unwraps

* fix test assertion
This commit is contained in:
Hubert
2022-10-04 16:14:07 +02:00
committed by GitHub
parent c453a88c99
commit 233d03ea75
2 changed files with 89 additions and 31 deletions

View File

@@ -7,11 +7,12 @@ struct CmdArgs {
#[clap(short, long)]
mac: Option<String>,
}
fn main() {
fn main() -> wakey::Result<()> {
let args = CmdArgs::parse();
if let Some(m) = args.mac {
let sep = m.chars().find(|ch| *ch == ':' || *ch == '-').unwrap_or('/');
let wol = wakey::WolPacket::from_string(&m, sep);
let wol = wakey::WolPacket::from_string(&m, sep)?;
if wol.send_magic().is_ok() {
println!("sent the magic packet.");
} else {
@@ -20,4 +21,6 @@ fn main() {
} else {
println!("give mac address to wake up");
}
Ok(())
}