use std::io;
use std::process::ExitCode;

use clap::Parser;

use rs_x2sheets::INPUT_BYTES_LIIMT_DEFAULT;
use rs_x2sheets::stdin2bytes2sheets2stdout;

#[derive(Parser)]
struct Cli {
    /// Maximum bytes to read from stdin
    #[arg(long, default_value_t = INPUT_BYTES_LIIMT_DEFAULT)]
    max_input_bytes: u64,
}

fn sub() -> Result<(), io::Error> {
    let args = Cli::parse();
    stdin2bytes2sheets2stdout(args.max_input_bytes)?;
    Ok(())
}

fn main() -> ExitCode {
    sub().map(|_| ExitCode::SUCCESS).unwrap_or_else(|e| {
        eprintln!("{e}");
        ExitCode::FAILURE
    })
}
