@@ -5,6 +5,7 @@ mod errors;
55mod svd_test;
66mod tests;
77
8+ use clap:: Parser ;
89use error_chain:: ChainedError ;
910use rayon:: prelude:: * ;
1011use std:: fs:: File ;
@@ -13,92 +14,91 @@ use std::path::PathBuf;
1314use std:: process:: { exit, Command } ;
1415use std:: sync:: atomic:: { AtomicBool , Ordering } ;
1516use std:: time:: Instant ;
16- use structopt:: StructOpt ;
1717
18- #[ derive( StructOpt , Debug ) ]
19- #[ structopt ( name = "svd2rust-regress" ) ]
18+ #[ derive( Parser , Debug ) ]
19+ #[ command ( name = "svd2rust-regress" ) ]
2020struct Opt {
2121 /// Run a long test (it's very long)
22- #[ structopt ( short = "l" , long = "long-test" ) ]
22+ #[ clap ( short = 'l' , long) ]
2323 long_test : bool ,
2424
2525 /// Path to an `svd2rust` binary, relative or absolute.
2626 /// Defaults to `target/release/svd2rust[.exe]` of this repository
2727 /// (which must be already built)
28- #[ structopt ( short = "p" , long = "svd2rust-path" , parse ( from_os_str ) ) ]
28+ #[ clap ( short = 'p' , long = "svd2rust-path" ) ]
2929 bin_path : Option < PathBuf > ,
3030
3131 // TODO: Consider using the same strategy cargo uses for passing args to rustc via `--`
3232 /// Run svd2rust with `--atomics`
33- #[ structopt ( long = "atomics" ) ]
33+ #[ clap ( long) ]
3434 atomics : bool ,
3535
3636 /// 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) ]
3838 chip : Vec < String > ,
3939
4040 /// Filter by manufacturer, case sensitive, may be combined with other filters
41- #[ structopt (
42- short = "m" ,
41+ #[ clap (
42+ short = 'm' ,
4343 long = "manufacturer" ,
44- raw ( validator = " validate_manufacturer" )
44+ value_parser = validate_manufacturer,
4545 ) ]
4646 mfgr : Option < String > ,
4747
4848 /// Filter by architecture, case sensitive, may be combined with other filters
4949 /// Options are: "CortexM", "RiscV", "Msp430", "Mips" and "XtensaLX"
50- #[ structopt (
51- short = "a" ,
50+ #[ clap (
51+ short = 'a' ,
5252 long = "architecture" ,
53- raw ( validator = " validate_architecture" )
53+ value_parser = validate_architecture,
5454 ) ]
5555 arch : Option < String > ,
5656
5757 /// Include tests expected to fail (will cause a non-zero return code)
58- #[ structopt ( short = "b" , long = "bad-tests" ) ]
58+ #[ clap ( short = 'b' , long) ]
5959 bad_tests : bool ,
6060
6161 /// Enable formatting with `rustfmt`
62- #[ structopt ( short = "f" , long = "format" ) ]
62+ #[ clap ( short = 'f' , long) ]
6363 format : bool ,
6464
6565 /// Print all available test using the specified filters
66- #[ structopt ( long = "list" ) ]
66+ #[ clap ( long) ]
6767 list : bool ,
6868
6969 /// Path to an `rustfmt` binary, relative or absolute.
7070 /// Defaults to `$(rustup which rustfmt)`
71- #[ structopt ( long = "rustfmt_bin_path" , parse ( from_os_str ) ) ]
71+ #[ clap ( long) ]
7272 rustfmt_bin_path : Option < PathBuf > ,
7373
7474 /// Specify what rustup toolchain to use when compiling chip(s)
75- #[ structopt ( long = "toolchain" , env = "RUSTUP_TOOLCHAIN" ) ]
75+ #[ clap ( long = "toolchain" ) ] // , env = "RUSTUP_TOOLCHAIN"
7676 rustup_toolchain : Option < String > ,
7777
7878 /// Use verbose output
79- #[ structopt ( long = "verbose" , short = "v" , parse ( from_occurrences ) ) ]
79+ #[ clap ( long, short = 'v' , action = clap :: ArgAction :: Count ) ]
8080 verbose : u8 ,
8181 // TODO: Specify smaller subset of tests? Maybe with tags?
8282 // TODO: Compile svd2rust?
8383}
8484
85- fn validate_chips ( s : String ) -> Result < ( ) , String > {
85+ fn validate_chips ( s : & str ) -> Result < ( ) , String > {
8686 if tests:: TESTS . iter ( ) . any ( |t| t. chip == s) {
8787 Ok ( ( ) )
8888 } else {
8989 Err ( format ! ( "Chip `{}` is not a valid value" , s) )
9090 }
9191}
9292
93- fn validate_architecture ( s : String ) -> Result < ( ) , String > {
93+ fn validate_architecture ( s : & str ) -> Result < ( ) , String > {
9494 if tests:: TESTS . iter ( ) . any ( |t| format ! ( "{:?}" , t. arch) == s) {
9595 Ok ( ( ) )
9696 } else {
9797 Err ( format ! ( "Architecture `{s}` is not a valid value" ) )
9898 }
9999}
100100
101- fn validate_manufacturer ( s : String ) -> Result < ( ) , String > {
101+ fn validate_manufacturer ( s : & str ) -> Result < ( ) , String > {
102102 if tests:: TESTS . iter ( ) . any ( |t| format ! ( "{:?}" , t. mfgr) == s) {
103103 Ok ( ( ) )
104104 } else {
@@ -140,7 +140,7 @@ fn read_file(path: &PathBuf, buf: &mut String) {
140140}
141141
142142fn main ( ) {
143- let opt = Opt :: from_args ( ) ;
143+ let opt = Opt :: parse ( ) ;
144144
145145 // Validate all test pre-conditions
146146 validate_tests ( tests:: TESTS ) ;
0 commit comments