use anyhow::Result;
use clap::Parser;
use log::info;
use std::io::{self, BufRead, BufReader};
use whippyunits_lsp_proxy::DisplayConfig;
use whippyunits_pretty::rustc_pretty::RustcPrettyPrinter;
#[derive(Parser, Debug)]
#[command(author, version, about, long_about = None)]
struct Args {
#[arg(short, long)]
verbose: bool,
#[arg(short, long)]
no_unicode: bool,
#[arg(short = 'r', long)]
include_raw: bool,
#[arg(short, long)]
debug: bool,
#[arg(short = 'f', long)]
input: Option<String>,
}
#[tokio::main]
async fn main() -> Result<()> {
let args = Args::parse();
if args.debug {
std::env::set_var("RUST_LOG", "debug");
}
env_logger::init();
info!("🚀 WHIPPYUNITS PRETTY PRINTER STARTING");
let display_config = DisplayConfig {
verbose: args.verbose,
unicode: !args.no_unicode,
include_raw: args.include_raw,
};
let mut printer = RustcPrettyPrinter::with_config(display_config);
if let Some(input_file) = args.input {
let content = std::fs::read_to_string(&input_file)?;
let processed = printer.process_rustc_output(&content)?;
print!("{}", processed);
} else {
let stdin = io::stdin();
let reader = BufReader::new(stdin.lock());
for line in reader.lines() {
let line = line?;
let processed = printer.process_line(&line)?;
println!("{}", processed);
}
}
Ok(())
}