diff --git a/Cargo.toml b/Cargo.toml index 6dc393a..1bb8d94 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,3 +16,4 @@ strum = "0.24.0" strum_macros = "0.24.0" itertools = "0.10.3" default-env = "0.1" +regex = "1.6.0" diff --git a/src/lib.rs b/src/lib.rs index 4d3b109..b403ccf 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -2,6 +2,7 @@ //! Homepage: use std::io::{Error, ErrorKind, Read}; use std::process::ExitStatus; +use regex::Regex; use std::str::FromStr; use strum_macros::EnumString; @@ -131,11 +132,13 @@ pub fn list_units( } let mut result: Vec = Vec::new(); let content = systemctl_capture(args)?; - let lines = content.lines(); - for l in lines.skip(1) { - // header labels - let parsed: Vec<_> = l.split_ascii_whitespace().collect(); - if parsed.len() == 2 { + let mut lines = content.lines(); + let seperator = Regex::new("\\s{2,}").unwrap(); + let header = lines.next().unwrap(); + let header_len = seperator.split(header).count(); + for l in lines.skip(1) { // header labels + let parsed : Vec<_> = l.split_ascii_whitespace().collect(); + if parsed.len() == header_len { result.push(parsed[0].to_string()) } }