diff --git a/src/cli.rs b/src/cli.rs index 35dd1de..c2fb810 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -6,7 +6,7 @@ use openssl::{ bn::{BigNum, MsbOption}, ec::{EcGroup, EcPoint}, }; -use serde_json::from_reader; +use serde_json::{from_reader, from_str}; use crate::{bink1998, crypto::initialize_elliptic_curve}; @@ -35,8 +35,8 @@ pub struct Options { num_keys: i32, /// Specify which keys file to load - #[arg(short = 'f', long = "file", default_value = "keys.json")] - keys_filename: String, + #[arg(short = 'f', long = "file")] + keys_filename: Option, /// Installation ID used to generate confirmation ID #[arg(short, long)] @@ -137,21 +137,28 @@ impl Cli { } fn validate_command_line(options: &mut Options) -> Result { - if options.verbose { - println!("Loading keys file {}", options.keys_filename); - } + let keys = { + if let Some(filename) = &options.keys_filename { + if options.verbose { + println!("Loading keys file {}", filename); + } - let keys = Self::load_json(&options.keys_filename)?; + let keys = Self::load_json(filename)?; - if options.verbose { - println!("Loaded keys from {} successfully", options.keys_filename); - } + if options.verbose { + println!("Loaded keys from {} successfully", filename); + } + + keys + } else { + from_str(std::include_str!("../keys.json"))? + } + }; if options.list { - let products = keys["Products"].as_object().ok_or(anyhow!( - "`Products` object not found in {}", - options.keys_filename - ))?; + let products = keys["Products"] + .as_object() + .ok_or(anyhow!("`Products` object not found in keys",))?; for (key, value) in products.iter() { println!("{}: {}", key, value["BINK"]); }