use std::path::Path;
use super::{
build::{build, build_in_memory},
fi,
init::init,
shorten::shorten,
transmute,
};
use crate::core::{CompiledCssInMemory, ConfigInMemory, CssOptimizer, GrimoireCssError};
#[derive(Debug, Clone, Copy, Default)]
pub struct CliOptions {
pub force_version_update: bool,
}
pub fn process_machine_readable_mode(args: &[String]) -> Option<Result<(), GrimoireCssError>> {
match args.get(1).map(String::as_str) {
Some("fi") => Some(fi::run_fi_cli(args.to_vec())),
Some("transmute") => Some(
transmute::run_transmute_cli(args.to_vec()).map_err(|error| {
eprintln!("Error: {error}");
error
}),
),
_ => None,
}
}
pub fn process_mode_and_handle<O: CssOptimizer>(
mode: &str,
current_dir: &Path,
css_optimizer: &O,
) -> Result<(), GrimoireCssError> {
process_mode_and_handle_with_options(mode, current_dir, css_optimizer, CliOptions::default())
}
pub fn process_mode_and_handle_with_options<O: CssOptimizer>(
mode: &str,
current_dir: &Path,
css_optimizer: &O,
options: CliOptions,
) -> Result<(), GrimoireCssError> {
match mode {
"init" => {
init(current_dir, mode)?;
}
"build" => {
build(
current_dir,
css_optimizer,
mode,
super::build::BuildOptions {
force_version_update: options.force_version_update,
},
)?;
}
"shorten" => {
shorten(current_dir)?;
}
_ => return Err(GrimoireCssError::InvalidInput(mode.to_string())),
}
Ok(())
}
pub fn handle_in_memory<O: CssOptimizer>(
config: &ConfigInMemory,
css_optimizer: &O,
) -> Result<Vec<CompiledCssInMemory>, GrimoireCssError> {
build_in_memory(css_optimizer, config)
}