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
//! CLI module for anyrepair //! //! Provides command handlers for the CLI interface pub mod repair_cmd; pub mod validate_cmd; pub mod batch_cmd; pub mod stream_cmd; use std::fs; use std::io::{self, Read}; /// Read content from file or stdin pub fn read_input(file_path: Option<&str>) -> io::Result<String> { match file_path { Some(path) => fs::read_to_string(path), None => { let mut buffer = String::new(); io::stdin().read_to_string(&mut buffer)?; Ok(buffer) } } } /// Write content to file or stdout pub fn write_output(content: &str, file_path: Option<&str>) -> io::Result<()> { match file_path { Some(path) => fs::write(path, content), None => { print!("{}", content); Ok(()) } } }