Added a function for truncating output
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful

This commit is contained in:
Gregory Ballantine 2022-08-07 09:37:33 -04:00
parent beffae7cd4
commit d967fc0920
4 changed files with 18 additions and 2 deletions

View File

@ -1,4 +1,5 @@
mod tests;
mod text;
use clap::{Args, Parser, Subcommand};

View File

@ -1,6 +1,8 @@
use chrono::prelude::*;
use std::{fs,process};
use crate::text;
// ping a host
pub fn ping_host(host: &str, count: &u16) {
println!("Pinging host {}, {} times.", host, count);
@ -15,8 +17,12 @@ pub fn ping_host(host: &str, count: &u16) {
// check that the command succeeded
assert!(output.status.success());
// print out the ping results from stdout
println!("{}", String::from_utf8_lossy(&output.stdout));
// grab the ping results from stdout
let results_raw = &String::from_utf8_lossy(&output.stdout);
let results = text::format::trim_output(results_raw, 4);
for line in results {
println!("{}", line);
}
}
// timed file copy test to guage bandwidth speeds

8
src/text/format.rs Normal file
View File

@ -0,0 +1,8 @@
use std::vec::Vec;
pub fn trim_output(text: &str, linecount: u16) -> Vec<&str> {
let text_vec: Vec<&str> = text.split("\n").collect();
let text_start = text_vec.len() - (linecount as usize);
let text_trim = text_vec.as_slice()[text_start..].to_vec();
return text_trim;
}

1
src/text/mod.rs Normal file
View File

@ -0,0 +1 @@
pub mod format;