summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/bin/r2md-prepend.rs50
1 files changed, 50 insertions, 0 deletions
diff --git a/src/bin/r2md-prepend.rs b/src/bin/r2md-prepend.rs
new file mode 100644
index 0000000..2649587
--- /dev/null
+++ b/src/bin/r2md-prepend.rs
@@ -0,0 +1,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")]
+ );
+ }
+}