@@ -16,6 +16,7 @@ use clap::{App, Arg};
1616use crate :: util:: { build_rs, Config , Target } ;
1717
1818fn run ( ) -> Result < ( ) > {
19+ use clap_conf:: prelude:: * ;
1920 use std:: io:: Read ;
2021
2122 let matches =
@@ -28,6 +29,13 @@ fn run() -> Result<()> {
2829 . takes_value ( true )
2930 . value_name ( "FILE" ) ,
3031 )
32+ . arg (
33+ Arg :: with_name ( "config" )
34+ . help ( "Config TOML file" )
35+ . short ( "c" )
36+ . takes_value ( true )
37+ . value_name ( "TOML_FILE" ) ,
38+ )
3139 . arg (
3240 Arg :: with_name ( "target" )
3341 . long ( "target" )
@@ -79,11 +87,6 @@ fn run() -> Result<()> {
7987
8088 setup_logging ( & matches) ;
8189
82- let target = matches
83- . value_of ( "target" )
84- . map ( |s| Target :: parse ( s) )
85- . unwrap_or_else ( || Ok ( Target :: default ( ) ) ) ?;
86-
8790 let xml = & mut String :: new ( ) ;
8891 match matches. value_of ( "input" ) {
8992 Some ( file) => {
@@ -103,15 +106,36 @@ fn run() -> Result<()> {
103106
104107 let device = svd:: parse ( xml) ?;
105108
106- let make_mod = matches. is_present ( "make_mod" ) ;
109+ let config_filename = matches. value_of ( "config" ) . unwrap_or ( "" ) ;
110+
111+ let cfg = with_toml_env ( & matches, & [ config_filename, "svd2rust.toml" ] ) ;
112+
113+ let target = cfg
114+ . grab ( )
115+ . arg ( "target" )
116+ . conf ( "target" )
117+ . done ( )
118+ . map ( |s| Target :: parse ( & s) )
119+ . unwrap_or_else ( || Ok ( Target :: default ( ) ) ) ?;
120+
121+ let nightly =
122+ cfg. bool_flag ( "nightly_features" , Filter :: Arg ) || cfg. bool_flag ( "nightly" , Filter :: Conf ) ;
123+ let generic_mod =
124+ cfg. bool_flag ( "generic_mod" , Filter :: Arg ) || cfg. bool_flag ( "generic_mod" , Filter :: Conf ) ;
125+ let make_mod =
126+ cfg. bool_flag ( "make_mod" , Filter :: Arg ) || cfg. bool_flag ( "make_mod" , Filter :: Conf ) ;
127+ let const_generic =
128+ cfg. bool_flag ( "const_generic" , Filter :: Arg ) || cfg. bool_flag ( "const_generic" , Filter :: Conf ) ;
129+ let ignore_groups =
130+ cfg. bool_flag ( "ignore_groups" , Filter :: Arg ) || cfg. bool_flag ( "ignore_groups" , Filter :: Conf ) ;
107131
108132 let config = Config {
109133 target,
110- nightly : matches . is_present ( "nightly_features" ) ,
111- generic_mod : matches . is_present ( "generic_mod" ) ,
134+ nightly,
135+ generic_mod,
112136 make_mod,
113- const_generic : matches . is_present ( "const_generic" ) ,
114- ignore_groups : matches . is_present ( "ignore_groups" ) ,
137+ const_generic,
138+ ignore_groups,
115139 } ;
116140
117141 let mut device_x = String :: new ( ) ;
0 commit comments