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 {
// 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");