buildah_rs/
parsing.rs

1/// Convenience macro that parses a line from a [`Command`]'s output.
2/// Returns Ok(stdout) if successful, otherwise returns Err(stderr).
3#[macro_export]
4macro_rules! parse_output {
5    ($output:expr) => {
6        {
7            let output = $output;
8
9            if !output.status.success() {
10                return Err(BuildahError::Buildah(parse_output_line(output.stderr)));
11            }
12
13            parse_output_line(output.stdout)
14        }
15    };
16}
17
18/// Converts a newline-terminated line of output into a String.
19/// Example: b"abc\n" => "abc"
20pub fn parse_output_line(bytes: Vec<u8>) -> String {
21    let string = String::from_utf8(bytes).unwrap();
22    string.trim_end().to_string()
23}
24
25#[cfg(test)]
26mod tests {
27    // TODO: test ^^
28
29    #[test]
30    fn it_works() {
31        assert_eq!(2 + 2, 4);
32    }
33}