summaryrefslogtreecommitdiff
path: root/src/bin/r2md-prepend.rs
blob: 26495872da9cb51666cf1c07104da1933d1759b2 (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::prepend_paths;

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

fn main() -> io::Result<()> {
    let cli = Cli::parse();
    prepend_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-prepend"]).unwrap();

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

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

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

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

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