mod commands;
mod engine;
mod html;
mod process;
mod themes;
mod unwrap;
use std::process::ExitCode;
use clap::{Parser, Subcommand};
#[derive(Debug)]
pub struct Fail {
pub message: String,
}
impl Fail {
pub fn new(message: impl Into<String>) -> Self {
Fail {
message: message.into(),
}
}
}
impl From<std::io::Error> for Fail {
fn from(e: std::io::Error) -> Self {
Fail::new(e.to_string())
}
}
impl From<kazari_rs::Error> for Fail {
fn from(e: kazari_rs::Error) -> Self {
Fail::new(e.to_string())
}
}
#[derive(Parser)]
#[command(
name = "kazari",
bin_name = "kazari",
version,
disable_version_flag = true,
about = "Framed, syntax highlighted code blocks with VS Code themes: upgrade built HTML sites, or render code, Markdown and Typst.",
after_help = "Run \"kazari <command> --help\" for the flags of a command."
)]
struct Cli {
#[command(subcommand)]
command: Command,
}
#[derive(Subcommand)]
enum Command {
Process(commands::process::ProcessArgs),
Render(commands::render::RenderArgs),
Markdown(commands::markdown::MarkdownArgs),
Typst(commands::typst::TypstArgs),
Css(engine::EngineArgs),
Js(engine::EngineArgs),
Themes,
Languages,
Version,
}
fn main() -> ExitCode {
let cli = Cli::parse();
let result = match cli.command {
Command::Process(args) => commands::process::run(args),
Command::Render(args) => commands::render::run(args),
Command::Markdown(args) => commands::markdown::run(args),
Command::Typst(args) => commands::typst::run(args),
Command::Css(args) => commands::assets::run_css(args),
Command::Js(args) => commands::assets::run_js(args),
Command::Themes => commands::list::run_themes(),
Command::Languages => commands::list::run_languages(),
Command::Version => {
println!("kazari {}", env!("CARGO_PKG_VERSION"));
Ok(0)
}
};
match result {
Ok(code) => ExitCode::from(code),
Err(fail) => {
eprintln!("kazari: {}", fail.message);
ExitCode::from(2)
}
}
}
pub fn highlighter() -> Result<irosashi::Highlighter, Fail> {
irosashi::Highlighter::new().map_err(|e| Fail::new(format!("initializing highlighter: {e}")))
}