@@ -5,6 +5,7 @@ mod errors;
5
5
mod svd_test;
6
6
mod tests;
7
7
8
+ use clap:: Parser ;
8
9
use error_chain:: ChainedError ;
9
10
use rayon:: prelude:: * ;
10
11
use std:: fs:: File ;
@@ -13,92 +14,91 @@ use std::path::PathBuf;
13
14
use std:: process:: { exit, Command } ;
14
15
use std:: sync:: atomic:: { AtomicBool , Ordering } ;
15
16
use std:: time:: Instant ;
16
- use structopt:: StructOpt ;
17
17
18
- #[ derive( StructOpt , Debug ) ]
19
- #[ structopt ( name = "svd2rust-regress" ) ]
18
+ #[ derive( Parser , Debug ) ]
19
+ #[ command ( name = "svd2rust-regress" ) ]
20
20
struct Opt {
21
21
/// Run a long test (it's very long)
22
- #[ structopt ( short = "l" , long = "long-test" ) ]
22
+ #[ clap ( short = 'l' , long) ]
23
23
long_test : bool ,
24
24
25
25
/// Path to an `svd2rust` binary, relative or absolute.
26
26
/// Defaults to `target/release/svd2rust[.exe]` of this repository
27
27
/// (which must be already built)
28
- #[ structopt ( short = "p" , long = "svd2rust-path" , parse ( from_os_str ) ) ]
28
+ #[ clap ( short = 'p' , long = "svd2rust-path" ) ]
29
29
bin_path : Option < PathBuf > ,
30
30
31
31
// TODO: Consider using the same strategy cargo uses for passing args to rustc via `--`
32
32
/// Run svd2rust with `--atomics`
33
- #[ structopt ( long = "atomics" ) ]
33
+ #[ clap ( long) ]
34
34
atomics : bool ,
35
35
36
36
/// Filter by chip name, case sensitive, may be combined with other filters
37
- #[ structopt ( short = "c" , long = "chip" , raw ( validator = " validate_chips" ) ) ]
37
+ #[ clap ( short = 'c' , long, value_parser = validate_chips) ]
38
38
chip : Vec < String > ,
39
39
40
40
/// Filter by manufacturer, case sensitive, may be combined with other filters
41
- #[ structopt (
42
- short = "m" ,
41
+ #[ clap (
42
+ short = 'm' ,
43
43
long = "manufacturer" ,
44
- raw ( validator = " validate_manufacturer" )
44
+ value_parser = validate_manufacturer,
45
45
) ]
46
46
mfgr : Option < String > ,
47
47
48
48
/// Filter by architecture, case sensitive, may be combined with other filters
49
49
/// Options are: "CortexM", "RiscV", "Msp430", "Mips" and "XtensaLX"
50
- #[ structopt (
51
- short = "a" ,
50
+ #[ clap (
51
+ short = 'a' ,
52
52
long = "architecture" ,
53
- raw ( validator = " validate_architecture" )
53
+ value_parser = validate_architecture,
54
54
) ]
55
55
arch : Option < String > ,
56
56
57
57
/// Include tests expected to fail (will cause a non-zero return code)
58
- #[ structopt ( short = "b" , long = "bad-tests" ) ]
58
+ #[ clap ( short = 'b' , long) ]
59
59
bad_tests : bool ,
60
60
61
61
/// Enable formatting with `rustfmt`
62
- #[ structopt ( short = "f" , long = "format" ) ]
62
+ #[ clap ( short = 'f' , long) ]
63
63
format : bool ,
64
64
65
65
/// Print all available test using the specified filters
66
- #[ structopt ( long = "list" ) ]
66
+ #[ clap ( long) ]
67
67
list : bool ,
68
68
69
69
/// Path to an `rustfmt` binary, relative or absolute.
70
70
/// Defaults to `$(rustup which rustfmt)`
71
- #[ structopt ( long = "rustfmt_bin_path" , parse ( from_os_str ) ) ]
71
+ #[ clap ( long) ]
72
72
rustfmt_bin_path : Option < PathBuf > ,
73
73
74
74
/// Specify what rustup toolchain to use when compiling chip(s)
75
- #[ structopt ( long = "toolchain" , env = "RUSTUP_TOOLCHAIN" ) ]
75
+ #[ clap ( long = "toolchain" ) ] // , env = "RUSTUP_TOOLCHAIN"
76
76
rustup_toolchain : Option < String > ,
77
77
78
78
/// Use verbose output
79
- #[ structopt ( long = "verbose" , short = "v" , parse ( from_occurrences ) ) ]
79
+ #[ clap ( long, short = 'v' , action = clap :: ArgAction :: Count ) ]
80
80
verbose : u8 ,
81
81
// TODO: Specify smaller subset of tests? Maybe with tags?
82
82
// TODO: Compile svd2rust?
83
83
}
84
84
85
- fn validate_chips ( s : String ) -> Result < ( ) , String > {
85
+ fn validate_chips ( s : & str ) -> Result < ( ) , String > {
86
86
if tests:: TESTS . iter ( ) . any ( |t| t. chip == s) {
87
87
Ok ( ( ) )
88
88
} else {
89
89
Err ( format ! ( "Chip `{}` is not a valid value" , s) )
90
90
}
91
91
}
92
92
93
- fn validate_architecture ( s : String ) -> Result < ( ) , String > {
93
+ fn validate_architecture ( s : & str ) -> Result < ( ) , String > {
94
94
if tests:: TESTS . iter ( ) . any ( |t| format ! ( "{:?}" , t. arch) == s) {
95
95
Ok ( ( ) )
96
96
} else {
97
97
Err ( format ! ( "Architecture `{s}` is not a valid value" ) )
98
98
}
99
99
}
100
100
101
- fn validate_manufacturer ( s : String ) -> Result < ( ) , String > {
101
+ fn validate_manufacturer ( s : & str ) -> Result < ( ) , String > {
102
102
if tests:: TESTS . iter ( ) . any ( |t| format ! ( "{:?}" , t. mfgr) == s) {
103
103
Ok ( ( ) )
104
104
} else {
@@ -140,7 +140,7 @@ fn read_file(path: &PathBuf, buf: &mut String) {
140
140
}
141
141
142
142
fn main ( ) {
143
- let opt = Opt :: from_args ( ) ;
143
+ let opt = Opt :: parse ( ) ;
144
144
145
145
// Validate all test pre-conditions
146
146
validate_tests ( tests:: TESTS ) ;
0 commit comments