use std::io::{self, Write};
use std::process::ExitCode;
use clap::Parser;
mod block;
mod cli;
mod completion;
mod config;
mod fm;
mod html;
mod inline;
mod json;
mod limits;
mod line_index;
mod lint;
mod lsp;
mod metadata;
mod server;
mod span;
mod structural;
mod toml;
mod validation;
mod workspace;
mod yaml;
#[cfg(test)]
mod encoding_tests;
#[cfg(test)]
mod property_tests;
#[cfg(any(test, feature = "fuzzing"))]
pub mod invariants;
#[cfg(feature = "fuzzing")]
pub mod fuzz_api;
#[must_use]
pub fn run() -> ExitCode {
let args = cli::Cli::parse();
match args.command {
cli::Command::Lint {
path,
strict,
quiet,
} => {
let mut stderr = io::stderr().lock();
match lint::run(&path, strict, quiet, &mut stderr) {
Ok(has_errors) => {
if has_errors {
ExitCode::from(1)
} else {
ExitCode::from(0)
}
}
Err(e) => {
let _ = writeln!(stderr, "error: {e:#}");
ExitCode::from(1)
}
}
}
cli::Command::Serve => match server::run() {
Ok(()) => ExitCode::from(0),
Err(e) => {
let _ = writeln!(io::stderr().lock(), "error: {e:#}");
ExitCode::from(1)
}
},
cli::Command::Config => {
let mut stdout = io::stdout().lock();
match writeln!(stdout, "{}", cli::CONFIG_REFERENCE) {
Ok(()) => ExitCode::from(0),
Err(e) => {
let _ = writeln!(io::stderr().lock(), "error: {e:#}");
ExitCode::from(1)
}
}
}
}
}