Added count argument to the Ping nettest subcommand; added short flags to nettest
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful

This commit is contained in:
Gregory Ballantine 2022-08-05 18:22:08 -04:00
parent 784f64ca16
commit 2cb744d654

View File

@ -14,15 +14,17 @@ struct Cli {
enum Commands { enum Commands {
// ping subcommand // ping subcommand
Ping { Ping {
#[clap(default_value_t = String::from("8.8.8.8"))] #[clap(short = 't', default_value_t = String::from("8.8.8.8"))]
host: String host: String,
#[clap(short = 'c', default_value_t = 30)]
count: u16,
}, },
// bandwidth test subcommand // bandwidth test subcommand
Bandwidth { 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, download: String,
#[clap(default_value_t = String::from("./tempfile"))] #[clap(short = 'o', default_value_t = String::from("./tempfile"))]
output: String, output: String,
}, },
} }
@ -32,19 +34,19 @@ fn main() {
// map subcommands back to the main command // map subcommands back to the main command
match &cli.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) Commands::Bandwidth { download, output } => bandwidth_test(download, output)
} }
} }
// ping a host // ping a host
fn ping_host(host: &str) { fn ping_host(host: &str, count: &u16) {
println!("Pinging host {}", host); println!("Pinging host {}, {} times.", host, count);
// run the ping command with 100 pings // run the ping command
let output = process::Command::new("ping") let output = process::Command::new("ping")
.arg(host) .arg(host)
.arg("-c 100") .arg(format!("-c {}", count))
.output() .output()
.expect("Failed to execute command"); .expect("Failed to execute command");