diff --git a/examples/dump.rs b/examples/dump.rs new file mode 100644 index 0000000..2dd6856 --- /dev/null +++ b/examples/dump.rs @@ -0,0 +1,20 @@ +//! Print the debug form of a parsed patch. + +use std::{ + env::args, + fs::read_to_string, + io::{stdin, Read}, +}; + +use gitpatch::Patch; + +fn main() { + let mut patch_text = String::new(); + if let Some(filename) = args().nth(1) { + patch_text = read_to_string(filename).unwrap(); + } else { + stdin().read_to_string(&mut patch_text).unwrap(); + }; + let patch = Patch::from_multiple(&patch_text).unwrap(); + println!("{:#?}", patch); +} diff --git a/examples/reproduce.rs b/examples/reproduce.rs new file mode 100644 index 0000000..013703a --- /dev/null +++ b/examples/reproduce.rs @@ -0,0 +1,22 @@ +//! Parse a patch from a file or stdin, then print it out as a patch. + +use std::{ + env::args, + fs::read_to_string, + io::{stdin, Read}, +}; + +use gitpatch::Patch; + +fn main() { + let mut patch_text = String::new(); + if let Some(filename) = args().nth(1) { + patch_text = read_to_string(filename).unwrap(); + } else { + stdin().read_to_string(&mut patch_text).unwrap(); + }; + let patches = Patch::from_multiple(&patch_text).unwrap(); + for patch in patches { + println!("{}", patch); + } +}