Skip to main content

autoconf_rs_cli/
lib.rs

1//! autoconf-rs-cli shared library.
2//!
3//! Provides the CLI argument parsing harness used by all 8 Autoconf binaries.
4//! Each binary is a thin wrapper that delegates to autoconf-rs-core.
5
6use std::io::Read;
7use std::path::PathBuf;
8
9/// Common result type for CLI operations.
10pub type CliResult = Result<(), String>;
11
12/// Read all of stdin into a String.
13pub fn read_stdin() -> Result<String, String> {
14    let mut buffer = String::new();
15    std::io::stdin()
16        .read_to_string(&mut buffer)
17        .map_err(|e| format!("error reading stdin: {}", e))?;
18    Ok(buffer)
19}
20
21/// Read a file into a String, or return stdin contents if path is "-".
22pub fn read_input(path: &str) -> Result<String, String> {
23    if path == "-" {
24        read_stdin()
25    } else {
26        std::fs::read_to_string(path).map_err(|e| format!("error reading {}: {}", path, e))
27    }
28}
29
30/// Common CLI options shared across Autoconf tools.
31#[derive(Debug, Default)]
32pub struct CommonOpts {
33    pub include_dirs: Vec<PathBuf>,
34    pub prepend_include_dirs: Vec<PathBuf>,
35    pub warnings: Vec<String>,
36    pub force: bool,
37    pub debug: bool,
38    pub verbose: bool,
39    pub output_file: Option<PathBuf>,
40}