whiskers.git / crates / whiskers-icons / src / bin / gen-kotlin.rs

Writes the admitted icons as Kotlin. gen-kotlin <out-file>; with no argument, prints it.

3fn main() {
4    let dir = std::path::Path::new(env!("CARGO_MANIFEST_DIR")).join("../../third-party/pixel-icons/icons");
5    let text = whiskers_icons::kotlin::generate(|id| {
6        std::fs::read_to_string(dir.join(format!("{id}.svg"))).map_err(|e| e.to_string())
7    })
8    .expect("every admitted icon reads and rasterises");
9    match std::env::args().nth(1) {
10        Some(path) => {
11            if let Some(parent) = std::path::Path::new(&path).parent() {
12                std::fs::create_dir_all(parent).expect("create the output directory");
13            }
14            std::fs::write(&path, text).expect("write the Kotlin file");
15        }
16        None => print!("{text}"),
17    }
18}