summaryrefslogtreecommitdiff
path: root/src/bin/r2md-append.rs
blob: 4cd2ae9e9d3f037de4de3f00c981df62d90a31e1 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
use std::{ffi::OsString, io};

use clap::Parser;
use repo2markdown::path_list_editor::append_paths;

/// Append paths to a null-separated file list from stdin.
#[derive(Debug, Parser)]
#[command(version, about, long_about = None)]
struct Cli {
    /// Paths to append to the input sequence.
    paths: Vec<OsString>,
}

fn main() -> io::Result<()> {
    let cli = Cli::parse();
    append_paths(io::stdin().lock(), io::stdout().lock(), &cli.paths)
}

#[cfg(test)]
mod tests {
    use std::ffi::OsString;

    use clap::Parser;

    use super::Cli;

    #[test]
    fn accepts_no_paths() {
        let cli = Cli::try_parse_from(["r2md-append"]).unwrap();

        assert_eq!(cli.paths, Vec::<OsString>::new());
    }

    #[test]
    fn accepts_one_path() {
        let cli = Cli::try_parse_from(["r2md-append", "README.md"]).unwrap();

        assert_eq!(cli.paths, vec![OsString::from("README.md")]);
    }

    #[test]
    fn accepts_multiple_paths() {
        let cli = Cli::try_parse_from(["r2md-append", "README.md", "src/main.rs"]).unwrap();

        assert_eq!(
            cli.paths,
            vec![OsString::from("README.md"), OsString::from("src/main.rs")]
        );
    }
}