diff --git a/src/nettest.rs b/src/nettest.rs index 9e93c7e..a75be85 100644 --- a/src/nettest.rs +++ b/src/nettest.rs @@ -14,15 +14,17 @@ struct Cli { enum Commands { // ping subcommand Ping { - #[clap(default_value_t = String::from("8.8.8.8"))] - host: String + #[clap(short = 't', default_value_t = String::from("8.8.8.8"))] + host: String, + #[clap(short = 'c', default_value_t = 30)] + count: u16, }, // bandwidth test subcommand Bandwidth { - #[clap(default_value_t = String::from("https://www.bitgoblin.tech/hardware-tests/export-01.mp4"))] + #[clap(short = 'd', default_value_t = String::from("https://www.bitgoblin.tech/hardware-tests/export-01.mp4"))] download: String, - #[clap(default_value_t = String::from("./tempfile"))] + #[clap(short = 'o', default_value_t = String::from("./tempfile"))] output: String, }, } @@ -32,19 +34,19 @@ fn main() { // map subcommands back to the main command match &cli.command { - Commands::Ping { host } => ping_host(host), + Commands::Ping { host, count } => ping_host(host, count), Commands::Bandwidth { download, output } => bandwidth_test(download, output) } } // ping a host -fn ping_host(host: &str) { - println!("Pinging host {}", host); +fn ping_host(host: &str, count: &u16) { + println!("Pinging host {}, {} times.", host, count); - // run the ping command with 100 pings + // run the ping command let output = process::Command::new("ping") .arg(host) - .arg("-c 100") + .arg(format!("-c {}", count)) .output() .expect("Failed to execute command");