@@ -7,7 +7,7 @@ use std::io::Write;
7
7
use std:: process;
8
8
9
9
use anyhow:: { Context , Result } ;
10
- use clap:: { Arg , Command } ;
10
+ use clap:: { Arg , ArgAction , Command } ;
11
11
12
12
use svd2rust:: {
13
13
generate, load_from,
@@ -18,11 +18,7 @@ fn parse_configs(app: Command) -> Result<Config> {
18
18
use irx_config:: parsers:: { cmd, toml} ;
19
19
use irx_config:: ConfigBuilder ;
20
20
let irxconfig = ConfigBuilder :: default ( )
21
- . append_parser (
22
- cmd:: ParserBuilder :: new ( app)
23
- . single_flags_as_bool ( true )
24
- . build ( ) ?,
25
- )
21
+ . append_parser ( cmd:: ParserBuilder :: new ( app) . build ( ) ?)
26
22
. append_parser (
27
23
toml:: ParserBuilder :: default ( )
28
24
. default_path ( "svd2rust.toml" )
@@ -38,116 +34,131 @@ fn parse_configs(app: Command) -> Result<Config> {
38
34
fn run ( ) -> Result < ( ) > {
39
35
use std:: io:: Read ;
40
36
41
- let log_help = format ! (
42
- "Choose which messages to log (overrides {})" ,
43
- env_logger:: DEFAULT_FILTER_ENV
44
- ) ;
45
-
46
37
let app = Command :: new ( "svd2rust" )
47
38
. about ( "Generate a Rust API from SVD files" )
48
39
. arg (
49
- Arg :: with_name ( "input" )
40
+ Arg :: new ( "input" )
50
41
. help ( "Input SVD file" )
51
42
. short ( 'i' )
52
- . takes_value ( true )
43
+ . action ( ArgAction :: Set )
53
44
. value_name ( "FILE" ) ,
54
45
)
55
46
. arg (
56
- Arg :: with_name ( "output_dir" )
47
+ Arg :: new ( "output_dir" )
57
48
. long ( "output-dir" )
58
49
. help ( "Directory to place generated files" )
59
50
. short ( 'o' )
60
- . takes_value ( true )
51
+ . action ( ArgAction :: Set )
61
52
. value_name ( "PATH" ) ,
62
53
)
63
54
. arg (
64
- Arg :: with_name ( "config" )
55
+ Arg :: new ( "config" )
65
56
. long ( "config" )
66
57
. help ( "Config TOML file" )
67
58
. short ( 'c' )
68
- . takes_value ( true )
59
+ . action ( ArgAction :: Set )
69
60
. value_name ( "TOML_FILE" ) ,
70
61
)
71
62
. arg (
72
- Arg :: with_name ( "target" )
63
+ Arg :: new ( "target" )
73
64
. long ( "target" )
74
65
. help ( "Target architecture" )
75
- . takes_value ( true )
66
+ . action ( ArgAction :: Set )
76
67
. value_name ( "ARCH" ) ,
77
68
)
78
69
. arg (
79
- Arg :: with_name ( "nightly" )
70
+ Arg :: new ( "nightly" )
80
71
. long ( "nightly" )
72
+ . action ( ArgAction :: SetTrue )
81
73
. help ( "Enable features only available to nightly rustc" ) ,
82
74
)
83
75
. arg (
84
- Arg :: with_name ( "const_generic" ) . long ( "const_generic" ) . help (
76
+ Arg :: new ( "const_generic" )
77
+ . long ( "const_generic" )
78
+ . action ( ArgAction :: SetTrue )
79
+ . help (
85
80
"Use const generics to generate writers for same fields with different offsets" ,
86
81
) ,
87
82
)
88
83
. arg (
89
- Arg :: with_name ( "ignore_groups" )
84
+ Arg :: new ( "ignore_groups" )
90
85
. long ( "ignore_groups" )
86
+ . action ( ArgAction :: SetTrue )
91
87
. help ( "Don't add alternateGroup name as prefix to register name" ) ,
92
88
)
93
- . arg ( Arg :: with_name ( "keep_list" ) . long ( "keep_list" ) . help (
89
+ . arg (
90
+ Arg :: new ( "keep_list" )
91
+ . long ( "keep_list" )
92
+ . action ( ArgAction :: SetTrue )
93
+ . help (
94
94
"Keep lists when generating code of dimElement, instead of trying to generate arrays" ,
95
95
) )
96
96
. arg (
97
- Arg :: with_name ( "generic_mod" )
97
+ Arg :: new ( "generic_mod" )
98
98
. long ( "generic_mod" )
99
99
. short ( 'g' )
100
+ . action ( ArgAction :: SetTrue )
100
101
. help ( "Push generic mod in separate file" ) ,
101
102
)
102
103
. arg (
103
- Arg :: with_name ( "feature_group" )
104
+ Arg :: new ( "feature_group" )
104
105
. long ( "feature_group" )
106
+ . action ( ArgAction :: SetTrue )
105
107
. help ( "Use group_name of peripherals as feature" ) ,
106
108
)
107
109
. arg (
108
- Arg :: with_name ( "feature_peripheral" )
110
+ Arg :: new ( "feature_peripheral" )
109
111
. long ( "feature_peripheral" )
112
+ . action ( ArgAction :: SetTrue )
110
113
. help ( "Use independent cfg feature flags for each peripheral" ) ,
111
114
)
112
115
. arg (
113
- Arg :: with_name ( "max_cluster_size" )
116
+ Arg :: new ( "max_cluster_size" )
114
117
. long ( "max_cluster_size" )
118
+ . action ( ArgAction :: SetTrue )
115
119
. help ( "Use array increment for cluster size" ) ,
116
120
)
117
121
. arg (
118
- Arg :: with_name ( "make_mod" )
122
+ Arg :: new ( "make_mod" )
119
123
. long ( "make_mod" )
120
124
. short ( 'm' )
125
+ . action ( ArgAction :: SetTrue )
121
126
. help ( "Create mod.rs instead of lib.rs, without inner attributes" ) ,
122
127
)
123
128
. arg (
124
- Arg :: with_name ( "strict" )
129
+ Arg :: new ( "strict" )
125
130
. long ( "strict" )
126
131
. short ( 's' )
132
+ . action ( ArgAction :: SetTrue )
127
133
. help ( "Make advanced checks due to parsing SVD" ) ,
128
134
)
129
135
. arg (
130
- Arg :: with_name ( "pascal_enum_values" )
136
+ Arg :: new ( "pascal_enum_values" )
131
137
. long ( "pascal_enum_values" )
138
+ . action ( ArgAction :: SetTrue )
132
139
. help ( "Use PascalCase in stead of UPPER_CASE for enumerated values" ) ,
133
140
)
134
141
. arg (
135
- Arg :: with_name ( "derive_more" )
142
+ Arg :: new ( "derive_more" )
136
143
. long ( "derive_more" )
144
+ . action ( ArgAction :: SetTrue )
137
145
. help ( "Use derive_more procedural macros to implement Deref and From" ) ,
138
146
)
139
147
. arg (
140
- Arg :: with_name ( "source_type" )
148
+ Arg :: new ( "source_type" )
141
149
. long ( "source_type" )
142
150
. help ( "Specify file/stream format" ) ,
143
151
)
144
152
. arg (
145
- Arg :: with_name ( "log_level" )
153
+ Arg :: new ( "log_level" )
146
154
. long ( "log" )
147
155
. short ( 'l' )
148
- . help ( log_help. as_ref ( ) )
149
- . takes_value ( true )
150
- . possible_values ( & [ "off" , "error" , "warn" , "info" , "debug" , "trace" ] ) ,
156
+ . help ( format ! (
157
+ "Choose which messages to log (overrides {})" ,
158
+ env_logger:: DEFAULT_FILTER_ENV
159
+ ) )
160
+ . action ( ArgAction :: Set )
161
+ . value_parser ( [ "off" , "error" , "warn" , "info" , "debug" , "trace" ] ) ,
151
162
)
152
163
. version ( concat ! (
153
164
env!( "CARGO_PKG_VERSION" ) ,
0 commit comments