@@ -15,54 +15,59 @@ use std::path::{Path, PathBuf};
15
15
use std:: process:: Command ;
16
16
use std:: str;
17
17
18
- use structopt :: StructOpt ;
18
+ use clap :: { CommandFactory , Parser } ;
19
19
20
20
#[ path = "test/mod.rs" ]
21
21
#[ cfg( test) ]
22
22
mod cargo_fmt_tests;
23
23
24
- #[ derive( StructOpt , Debug ) ]
25
- #[ structopt (
24
+ #[ derive( Parser ) ]
25
+ #[ clap (
26
26
bin_name = "cargo fmt" ,
27
27
about = "This utility formats all bin and lib files of \
28
28
the current crate using rustfmt."
29
29
) ]
30
30
pub struct Opts {
31
31
/// No output printed to stdout
32
- #[ structopt ( short = "q" , long = "quiet" ) ]
32
+ #[ clap ( short = 'q' , long = "quiet" ) ]
33
33
quiet : bool ,
34
34
35
35
/// Use verbose output
36
- #[ structopt ( short = "v" , long = "verbose" ) ]
36
+ #[ clap ( short = 'v' , long = "verbose" ) ]
37
37
verbose : bool ,
38
38
39
39
/// Print rustfmt version and exit
40
- #[ structopt ( long = "version" ) ]
40
+ #[ clap ( long = "version" ) ]
41
41
version : bool ,
42
42
43
43
/// Specify package to format
44
- #[ structopt( short = "p" , long = "package" , value_name = "package" ) ]
44
+ #[ clap(
45
+ short = 'p' ,
46
+ long = "package" ,
47
+ value_name = "package" ,
48
+ multiple_values = true
49
+ ) ]
45
50
packages : Vec < String > ,
46
51
47
52
/// Specify path to Cargo.toml
48
- #[ structopt ( long = "manifest-path" , value_name = "manifest-path" ) ]
53
+ #[ clap ( long = "manifest-path" , value_name = "manifest-path" ) ]
49
54
manifest_path : Option < String > ,
50
55
51
56
/// Specify message-format: short|json|human
52
- #[ structopt ( long = "message-format" , value_name = "message-format" ) ]
57
+ #[ clap ( long = "message-format" , value_name = "message-format" ) ]
53
58
message_format : Option < String > ,
54
59
55
60
/// Options passed to rustfmt
56
61
// 'raw = true' to make `--` explicit.
57
- #[ structopt ( name = "rustfmt_options" , raw( true ) ) ]
62
+ #[ clap ( name = "rustfmt_options" , raw( true ) ) ]
58
63
rustfmt_options : Vec < String > ,
59
64
60
65
/// Format all packages, and also their local path-based dependencies
61
- #[ structopt ( long = "all" ) ]
66
+ #[ clap ( long = "all" ) ]
62
67
format_all : bool ,
63
68
64
69
/// Run rustfmt in check mode
65
- #[ structopt ( long = "check" ) ]
70
+ #[ clap ( long = "check" ) ]
66
71
check : bool ,
67
72
}
68
73
@@ -87,7 +92,7 @@ fn execute() -> i32 {
87
92
}
88
93
} ) ;
89
94
90
- let opts = Opts :: from_iter ( args) ;
95
+ let opts = Opts :: parse_from ( args) ;
91
96
92
97
let verbosity = match ( opts. verbose , opts. quiet ) {
93
98
( false , false ) => Verbosity :: Normal ,
@@ -204,7 +209,7 @@ fn convert_message_format_to_rustfmt_args(
204
209
205
210
fn print_usage_to_stderr ( reason : & str ) {
206
211
eprintln ! ( "{}" , reason) ;
207
- let app = Opts :: clap ( ) ;
212
+ let app = Opts :: command ( ) ;
208
213
app. after_help ( "" )
209
214
. write_help ( & mut io:: stderr ( ) )
210
215
. expect ( "failed to write to stderr" ) ;
0 commit comments