diff --git a/examples/wifi-cli/Cargo.toml b/examples/wifi-cli/Cargo.toml new file mode 100644 index 0000000..55cdfdc --- /dev/null +++ b/examples/wifi-cli/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "wifi-cli" +version = "0.1.0" +authors = ["Tochukwu Nkemdilim "] + +[dependencies] +clap = { version = "2.31.2", features = ["yaml"] } +wifi-rs = { path = "../../../wifi-rs" } \ No newline at end of file diff --git a/examples/wifi-cli/src/main.rs b/examples/wifi-cli/src/main.rs new file mode 100644 index 0000000..d5409db --- /dev/null +++ b/examples/wifi-cli/src/main.rs @@ -0,0 +1,43 @@ +extern crate clap; +extern crate wifi_rs; + +use clap::{App, Arg}; +use std::io; +use wifi_rs::WiFi; + +fn main() -> Result<(), io::Error> { + let matches = App::new("Wi-Fi") + .version("0.0.1") + .author("Tochukwu Nkemdilim") + .about("Connect to a Wi-Fi network 🎉") + .arg( + Arg::with_name("ssid") + .short("s") + .long("ssid") + .multiple(false) + .required(true) + .takes_value(true) + .help("SSID of wireless network."), + ) + .arg( + Arg::with_name("password") + .short("p") + .long("password") + .multiple(false) + .required(true) + .takes_value(true) + .help("Password of the wireless network."), + ) + .get_matches(); + + // Get Password + let password = matches.value_of("password").unwrap(); + + // Get SSID + let ssid = matches.value_of("ssid").unwrap(); + + let wifi = WiFi::new(ssid)?; + println!("Connection Status: {}", wifi.connect(password)); + + Ok(()) +}