Merge pull request #2 from steady286/add_clap
Add Clap crate and a binary
This commit is contained in:
commit
7c79206849
|
@ -14,3 +14,4 @@ categories = ["network-programming"]
|
|||
|
||||
[dependencies]
|
||||
hex = "~0.3"
|
||||
clap = { version = "3.1.18", features = ["derive"] }
|
||||
|
|
|
@ -29,3 +29,11 @@ let dst = SocketAddr::from(([255,255,255,255], 9));
|
|||
|
||||
wol.send_magic_to(src, dst);
|
||||
```
|
||||
|
||||
## Included binary
|
||||
|
||||
The binary `bin/wake` may be directly used in scripts:
|
||||
|
||||
```
|
||||
wake -m 00:11:22:33:44:55
|
||||
```
|
||||
|
|
23
src/bin/wake.rs
Normal file
23
src/bin/wake.rs
Normal file
|
@ -0,0 +1,23 @@
|
|||
use clap::Parser;
|
||||
|
||||
#[derive(Parser)]
|
||||
#[clap(about = "WakeOnLan a device. https://github.com/LesnyRumcajs/wakey.git", long_about = None)]
|
||||
struct CmdArgs {
|
||||
/// mac address to send packet to
|
||||
#[clap(short, long)]
|
||||
mac: Option<String>,
|
||||
}
|
||||
fn main() {
|
||||
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.");
|
||||
}
|
||||
} else {
|
||||
println!("give mac address to wake up");
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user