pub fn minify(diff: &str) -> String {
    let minusplus = Regex::new(r"^\- |^\+ ").unwrap();
    let generation = Regex::new(r"generation[:]{1}").unwrap();
    let kind_line = Regex::new(r"--- /tmp/LIVE-[a-zA-Z0-9]+/([\w\.]+)").unwrap();
    // Find the +++/--- header and extract the type from it.
    // Then trim everything that doesn't start with `- ` or `+ `
    // and additionally ignore `generation` integer updates

    let mut res = vec![];
    let mut in_secret = false;
    for l in diff.lines() {
        if let Some(cap) = kind_line.captures(l) {
            in_secret = cap[1].contains("Secret");
            if in_secret {
                res.push(format!("Change to {} elided for security", &cap[1]));
            } else {
                res.push(format!("{} has changed:", &cap[1]));
            }
        } else if !in_secret && !l.starts_with("+++") && !generation.is_match(l) && minusplus.is_match(l) {
            res.push(l.to_string());
        }
    }
    res.join("\n")
}
/// Minify diff output from kubectl diff
Minify diff output from kubectl diff
Minify diff output from kubectl diff
pub fn minify(diff: &str) -> String {
    let minusplus = Regex::new(r"^\- |^\+ ").unwrap();
    let generation = Regex::new(r"generation[:]{1}").unwrap();
    let kind_line = Regex::new(r"--- /tmp/LIVE-[a-zA-Z0-9]+/([\w\.]+)").unwrap();
    // Find the +++/--- header and extract the type from it.
    // Then trim everything that doesn't start with `- ` or `+ `
    // and additionally ignore `generation` integer updates
    let mut res = vec![];
    let mut in_secret = false;
    for l in diff.lines() {
        if let Some(cap) = kind_line.captures(l) {
            in_secret = cap[1].contains("Secret");
            if in_secret {
                res.push(format!("Change to {} elided for security", &cap[1]));
            } else {
                res.push(format!("{} has changed:", &cap[1]));
            }
        } else if !in_secret && !l.starts_with("+++") && !generation.is_match(l) && minusplus.is_match(l) {
            res.push(l.to_string());
        }
    }
    res.join("\n")
}
pub fn minify ( diff : & str ) -> String { let minusplus = Regex :: new ( r"^\- |^\+ " ) . unwrap ( ) ; let generation = Regex :: new ( r"generation[:]{1}" ) . unwrap ( ) ; let kind_line = Regex :: new ( r"--- /tmp/LIVE-[a-zA-Z0-9]+/([\w\.]+)" ) . unwrap ( ) ; // Find the +++/--- header and extract the type from it. // Then trim everything that doesn't start with `- ` or `+ ` // and additionally ignore `generation` integer updates let mut res = vec ! [ ] ; let mut in_secret = false ; for l in diff . lines ( ) { if let Some ( cap ) = kind_line . captures ( l ) { in_secret = cap [ 1 ] . contains ( " " ) ; if in_secret { res . push ( format ! ( " " cap [ 1 ] ) ) ; } else { res . push ( format ! ( " " cap [ 1 ] ) ) ; } } else if ! in_secret && ! l . starts_with ( " " ) && ! generation . is_match ( l ) && minusplus . is_match ( l ) { res . push ( l . to_string ( ) ) ; } } res . join ( " \n " ) }
Minify diff output from kubectl diff
Minify diff output from kubectl diff
diff
&str
diff
&str