use serde::{Deserialize, Serialize};
use std::fs;
pub mod fusion;
use clap::{Parser, Subcommand};
#[derive(Debug, Deserialize, Serialize)]
struct IconInfo {
title: String,
#[serde(rename = "categoryTitle")]
category_title: String,
path: String,
category: String,
#[serde(rename = "titleKey")]
title_key: String,
#[serde(rename = "categoryKey")]
category_key: String,
}
pub fn process(path: &str, output: &str) -> Result<(), Box<dyn std::error::Error>> {
let reg = regex::Regex::new(r"\{.*\}")?;
let json_str = fs::read_to_string(path)?;
let res = reg
.find_iter(&json_str)
.map(|i| serde_json::from_str::<IconInfo>(i.as_str()).unwrap())
.collect::<Vec<_>>();
fs::write(output, serde_json::to_vec_pretty(&res).unwrap())?;
Ok(())
}
#[derive(Debug, Parser)]
#[command(author, version, about, long_about = None)]
pub struct ProcessJson {
#[command(subcommand)]
pub command: SubCommand,
}
#[derive(Debug, Subcommand)]
pub enum SubCommand {
Process {
#[arg(short, long)]
path: String,
#[arg(short, long)]
output: String,
},
Fusion,
}
impl SubCommand {
pub fn run(&self) -> Result<(), Box<dyn std::error::Error>> {
match self {
SubCommand::Process { path, output } => {
process(path, output)?;
}
SubCommand::Fusion => {
fusion::fusion_run()?;
}
}
Ok(())
}
}