@@ -3,6 +3,9 @@ use std::io::{Read, Write};
33use std:: str:: FromStr ;
44use std:: { fs:: File , path:: Path } ;
55
6+ use crate :: get_encoder_config;
7+ pub use crate :: ConfigFormat ;
8+
69#[ derive( Clone , Copy , Debug , PartialEq , Eq ) ]
710#[ non_exhaustive]
811pub enum InputFormat {
@@ -43,24 +46,6 @@ impl FromStr for OutputFormat {
4346 }
4447}
4548
46- #[ derive( Clone , Copy , Debug , PartialEq , Eq ) ]
47- #[ non_exhaustive]
48- pub enum ConfigFormat {
49- Yaml ,
50- Json ,
51- }
52-
53- impl FromStr for ConfigFormat {
54- type Err = anyhow:: Error ;
55- fn from_str ( s : & str ) -> Result < Self , Self :: Err > {
56- match s {
57- "yml" | "yaml" | "YAML" => Ok ( Self :: Yaml ) ,
58- "json" | "JSON" => Ok ( Self :: Json ) ,
59- _ => Err ( anyhow ! ( "Unknown config file format" ) ) ,
60- }
61- }
62- }
63-
6449pub struct ParserConfig {
6550 pub expand : bool ,
6651 pub expand_properties : bool ,
@@ -110,28 +95,7 @@ pub fn convert(
11095 device
11196 } ;
11297
113- let config = if let Some ( format_config) = format_config {
114- let config_format = match format_config. extension ( ) . and_then ( |e| e. to_str ( ) ) {
115- Some ( s) => ConfigFormat :: from_str ( s) ?,
116- _ => return Err ( anyhow ! ( "Unknown output file format" ) ) ,
117- } ;
118- let mut config = String :: new ( ) ;
119- File :: open ( format_config) ?. read_to_string ( & mut config) ?;
120-
121- let config_map: std:: collections:: HashMap < String , String > = match config_format {
122- ConfigFormat :: Yaml => serde_yaml:: from_str ( & config) ?,
123- ConfigFormat :: Json => serde_json:: from_str ( & config) ?,
124- } ;
125-
126- let mut config = svd_encoder:: Config :: default ( ) ;
127- config_map
128- . iter ( )
129- . for_each ( |( name, value) | config. update ( name, value) ) ;
130-
131- config
132- } else {
133- svd_encoder:: Config :: default ( )
134- } ;
98+ let config = get_encoder_config ( format_config) ?;
13599
136100 let output = match output_format {
137101 OutputFormat :: Xml => svd_encoder:: encode_with_config ( & device, & config) ?,
0 commit comments