echo_comment/
lib.rs

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