use clap::Parser;
use miette::Result as MietteResult;
use tale_ndjson::config::{ConfigOpts, InputMode};
#[cfg(debug_assertions)]
use tale_ndjson::json_profiler;
use tale_ndjson::{Args, config, multiplexed, readers};
#[tokio::main]
async fn main() -> MietteResult<()> {
let args = Args::parse();
let config = ConfigOpts::new(&args).unwrap_or_else(|e| {
eprintln!("Configuration error: {}", e);
std::process::exit(1);
});
config::set(config).expect("Quite improbably failed to set config OnceLock on process start.");
let mode = config::mode();
let result = match mode {
InputMode::Stdin => readers::handle_stdin(),
InputMode::SingleFile { path } => readers::handle_file(&path).await,
InputMode::MultiFile { paths } => {
if args.follow || args.sticky {
multiplexed::handle_tailing(paths).await
} else {
multiplexed::handle_static(paths)
}
}
};
#[cfg(debug_assertions)]
{
eprintln!();
json_profiler::print_report();
}
result
}