diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..a19a38e --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,19 @@ +# Changelog + +All notable changes to this project will be documented in this file. + +The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), +and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). + +## [0.3.0] - 2023-01-06 + + +### Added + +- this changelog :) + +### Changed + +- refactored the interface and internals a bit. In short, the library should no longer panic on any errors and should return a sane `Result` so it can be handled by the crate user. +- made methods `WolPacket::from_string` and `WolPacket::mac_to_byte` more flexible by making the `data` an `AsRef`. +- `wakey-wake` no longer needs an `-m` or `--mac` flag. The adress is now a positional argument so just call the binary with the appropriate address. diff --git a/README.md b/README.md index 2ffed91..6b576b0 100644 --- a/README.md +++ b/README.md @@ -11,11 +11,11 @@ Library for managing Wake-on-LAN packets. It supports: From string representation of MAC address and using defaults when broadcasting: ```rust -let wol = wakey::WolPacket::from_string("01:02:03:04:05:06", ':'); +let wol = wakey::WolPacket::from_string(&mac_adress, sep)?; if wol.send_magic().is_ok() { - println!("Sent the magic packet!"); + println!("Sent the magic packet."); } else { - println!("Failed to send the magic packet!"); + println!("Failed to send the magic packet."); } ``` @@ -23,15 +23,15 @@ Packets can also be constructed with raw bytes and sent from / to custom address ```rust use std::net::SocketAddr; -let wol = wakey::WolPacket::from_bytes(&[0x00, 0x01, 0x02, 0x03, 0x04, 0x05]); +let wol = wakey::WolPacket::from_bytes(&[0x00, 0x01, 0x02, 0x03, 0x04, 0x05])?; let src = SocketAddr::from(([0,0,0,0], 0)); let dst = SocketAddr::from(([255,255,255,255], 9)); -wol.send_magic_to(src, dst); +wol.send_magic_to(src, dst)?; ``` ## Included binary ``` -cargo run --bin wakey-wake -m 00:11:22:33:44:55 +cargo run --bin wakey-wake 00:11:22:33:44:55 ``` diff --git a/wakey-wake/Cargo.toml b/wakey-wake/Cargo.toml index b51877c..7196507 100644 --- a/wakey-wake/Cargo.toml +++ b/wakey-wake/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "wakey-wake" -version = "0.2.2" +version = "0.3.0" authors = ["Hubert Bugaj"] edition = "2021" @@ -14,4 +14,4 @@ categories = ["network-programming"] [dependencies] wakey = { path = "../wakey" } -clap = { version = "4.0.15", features = ["derive"] } +clap = { version = "4.0", features = ["derive"] } diff --git a/wakey-wake/src/main.rs b/wakey-wake/src/main.rs index aa9e261..51008ba 100644 --- a/wakey-wake/src/main.rs +++ b/wakey-wake/src/main.rs @@ -1,25 +1,24 @@ use clap::Parser; #[derive(Parser)] -#[clap(about = "WakeOnLan a device. https://github.com/LesnyRumcajs/wakey.git", long_about = None)] +#[clap(author, version, about, long_about = None)] struct CmdArgs { - /// mac address to send packet to - #[clap(short, long)] - mac: Option, + /// MAC address to send packet to. Should be in format AA:BB:CC:DD:EE:FF, AA-BB-CC-DD-EE-FF or + /// AA/BB/CC/DD/EE/FF. + mac_address: String, } 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)?; - if wol.send_magic().is_ok() { - println!("sent the magic packet."); - } else { - println!("failed to send the magic packet."); - } + let mac_adress = CmdArgs::parse().mac_address; + let sep = mac_adress + .chars() + .find(|ch| *ch == ':' || *ch == '-' || *ch == '/') + .expect("Invalid MAC address format. Please use one of the separators: [:, -, /]"); + let wol = wakey::WolPacket::from_string(&mac_adress, sep)?; + if wol.send_magic().is_ok() { + println!("Sent the magic packet."); } else { - println!("give mac address to wake up"); + println!("Failed to send the magic packet."); } Ok(()) diff --git a/wakey/Cargo.toml b/wakey/Cargo.toml index c03800f..05e413e 100644 --- a/wakey/Cargo.toml +++ b/wakey/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "wakey" -version = "0.2.2" +version = "0.3.0" authors = ["Hubert Bugaj"] edition = "2021"