factorio_blueprint/src/bin/decode_blueprint.rs

29 lines
699 B
Rust

use base64::prelude::*;
use clap::Parser;
use factorio_blueprint::blueprint::{decode, encode};
use std::path::PathBuf;
#[derive(Debug, Parser)]
struct Args {
filename: PathBuf,
#[arg(short, long)]
encode: bool,
}
fn main() {
let args = Args::parse();
let s = std::fs::read_to_string(args.filename).unwrap();
if args.encode {
let j: serde_json::Value = serde_json::from_str(&s).unwrap();
let d = encode(&serde_json::to_string(&j).unwrap());
println!("{}", d);
} else {
let d = decode(&s);
let j: serde_json::Value = serde_json::from_str(&d).unwrap();
println!("{}", serde_json::to_string_pretty(&j).unwrap());
}
}