mod build;
mod clean;
mod compile;
mod init;
use std::path::PathBuf;
use anyhow::Result;
use clap::{Parser, Subcommand};
use log::LevelFilter;
use crate::Logger;
#[derive(Parser)]
#[command(author, version, about)]
struct Djoc {
#[command(subcommand)]
command: Command,
#[arg(global = true, short, long)]
quiet: bool,
#[arg(global = true, short, long)]
debug: bool,
}
#[derive(Debug, Subcommand)]
enum Command {
Build,
Clean,
Compile {
path: Option<PathBuf>,
#[arg(short, long, default_value = "pdf")]
format: String,
#[arg(short, long)]
output: Option<String>,
#[arg(long, default_value = "false")]
number_sections: bool,
},
Init {
path: Option<PathBuf>,
},
}
pub fn run() -> Result<()> {
let app = Djoc::parse();
let logger = match (app.quiet, app.debug) {
(true, _) => Logger::new(LevelFilter::Error),
(_, true) => Logger::new(LevelFilter::Off),
_ => Logger::new(LevelFilter::Info),
};
log::set_max_level(logger.filter);
log::set_boxed_logger(Box::new(logger))?;
match app.command {
Command::Build => build::build()?,
Command::Clean => clean::clean()?,
Command::Compile {
path,
format,
output,
number_sections,
} => compile::compile(path, format, output, number_sections)?,
Command::Init { path } => init::init(path)?,
}
Ok(())
}