glossa_cli/
parser.rs

1use std::fs;
2
3use clap::Parser;
4use glossa::{MiniStr, fallback::dbg_ref};
5use glossa_codegen::{AnyResult, glossa_shared::tap::Pipe, highlight::KString};
6mod collect;
7mod init;
8mod output;
9mod resources;
10
11use crate::{options::Cli, parser::output::output_data, static_data};
12
13impl Cli {
14  pub fn run() -> AnyResult<()> {
15    let args = Cli::parse();
16    dbg_ref!(args);
17
18    if *args
19      .get_dbg_options()
20      .get_display_config_dir()
21    {
22      println!("{:?}", static_data::config_dir());
23    }
24
25    let generator = init::init_generator(&args)
26      .with_resources(init::init_resources(&args))
27      .pipe(|res| match init::init_highlight_cfg_map(&args) {
28        Some(x) => res.with_highlight(x),
29        _ => res,
30      });
31    dbg_ref!(generator);
32
33    if let Some(dir) = generator.get_outdir() {
34      log::info!("output dir: {dir:?}");
35      fs::create_dir_all(dir)?;
36    }
37
38    output_data(&args, &generator)?;
39
40    Ok(())
41  }
42}
43
44fn to_kstr(s: &MiniStr) -> KString {
45  KString::from_ref(s)
46}