echo_comment/
lib.rs

1use std::fs;
2
3pub mod cli;
4pub mod error;
5pub mod processor;
6pub mod runner;
7
8pub use error::{EchoCommentError, Result};
9pub use processor::{Mode, process_script_content};
10pub use runner::ScriptRunner;
11
12macro_rules! debug {
13    ($($arg:tt)*) => {
14        if std::env::var("ECHO_COMMENT_DEBUG").is_ok() {
15            eprintln!($($arg)*);
16        }
17    };
18}
19
20pub(crate) use debug;
21
22/// Main entry point for processing and running a script
23pub fn run_script(script_path: &str, script_args: &[String], mode: Mode) -> Result<()> {
24    debug!("Processing script: {} in mode: {:?}", script_path, mode);
25
26    // Read the input script
27    let content = fs::read_to_string(script_path).map_err(|e| EchoCommentError::FileRead {
28        path: script_path.to_string(),
29        source: e,
30    })?;
31
32    // Process the content
33    let processed_content = process_script_content(&content, mode)?;
34
35    // Run the processed script
36    let runner = ScriptRunner::new();
37    runner.run_script(&processed_content, script_args)?;
38
39    Ok(())
40}