diff --git a/src/main.rs b/src/main.rs index 83a482a..af3975f 100755 --- a/src/main.rs +++ b/src/main.rs @@ -42,7 +42,7 @@ struct ExtractPeripheral { peripheral: String, /// Transforms file path #[clap(long)] - transform: Option, + transform: Vec, } /// Extract all peripherals from SVD to YAML @@ -78,7 +78,7 @@ struct Generate { svd: String, /// Transforms file path #[clap(long)] - transform: Option, + transform: Vec, } /// Reformat a YAML @@ -156,9 +156,13 @@ fn load_config(path: &str) -> Result { } fn extract_peripheral(args: ExtractPeripheral) -> Result<()> { - let config = match args.transform { - Some(s) => load_config(&s)?, - None => Config::default(), + let config = if args.transform.is_empty() { + Config::default() + } else { + args.transform + .into_iter() + .map(|s| load_config(&s)) + .collect::>()? }; let svd = load_svd(&args.svd)?; @@ -247,9 +251,13 @@ fn extract_all(args: ExtractAll) -> Result<()> { } fn gen(args: Generate) -> Result<()> { - let config = match args.transform { - Some(s) => load_config(&s)?, - None => Config::default(), + let config = if args.transform.is_empty() { + Config::default() + } else { + args.transform + .into_iter() + .map(|s| load_config(&s)) + .collect::>()? }; let svd = load_svd(&args.svd)?; @@ -400,6 +408,13 @@ struct Config { transforms: Vec, } +impl FromIterator for Config { + fn from_iter>(iter: I) -> Self { + let transforms: Vec<_> = iter.into_iter().flat_map(|c| c.transforms).collect(); + Self { transforms } + } +} + impl Default for Config { fn default() -> Self { Self { transforms: vec![] }