@@ -15,54 +15,59 @@ use std::path::{Path, PathBuf};
1515use std:: process:: Command ;
1616use std:: str;
1717
18- use structopt :: StructOpt ;
18+ use clap :: { CommandFactory , Parser } ;
1919
2020#[ path = "test/mod.rs" ]
2121#[ cfg( test) ]
2222mod cargo_fmt_tests;
2323
24- #[ derive( StructOpt , Debug ) ]
25- #[ structopt (
24+ #[ derive( Parser ) ]
25+ #[ clap (
2626 bin_name = "cargo fmt" ,
2727 about = "This utility formats all bin and lib files of \
2828 the current crate using rustfmt."
2929) ]
3030pub struct Opts {
3131 /// No output printed to stdout
32- #[ structopt ( short = "q" , long = "quiet" ) ]
32+ #[ clap ( short = 'q' , long = "quiet" ) ]
3333 quiet : bool ,
3434
3535 /// Use verbose output
36- #[ structopt ( short = "v" , long = "verbose" ) ]
36+ #[ clap ( short = 'v' , long = "verbose" ) ]
3737 verbose : bool ,
3838
3939 /// Print rustfmt version and exit
40- #[ structopt ( long = "version" ) ]
40+ #[ clap ( long = "version" ) ]
4141 version : bool ,
4242
4343 /// 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+ ) ]
4550 packages : Vec < String > ,
4651
4752 /// Specify path to Cargo.toml
48- #[ structopt ( long = "manifest-path" , value_name = "manifest-path" ) ]
53+ #[ clap ( long = "manifest-path" , value_name = "manifest-path" ) ]
4954 manifest_path : Option < String > ,
5055
5156 /// Specify message-format: short|json|human
52- #[ structopt ( long = "message-format" , value_name = "message-format" ) ]
57+ #[ clap ( long = "message-format" , value_name = "message-format" ) ]
5358 message_format : Option < String > ,
5459
5560 /// Options passed to rustfmt
5661 // 'raw = true' to make `--` explicit.
57- #[ structopt ( name = "rustfmt_options" , raw( true ) ) ]
62+ #[ clap ( name = "rustfmt_options" , raw( true ) ) ]
5863 rustfmt_options : Vec < String > ,
5964
6065 /// Format all packages, and also their local path-based dependencies
61- #[ structopt ( long = "all" ) ]
66+ #[ clap ( long = "all" ) ]
6267 format_all : bool ,
6368
6469 /// Run rustfmt in check mode
65- #[ structopt ( long = "check" ) ]
70+ #[ clap ( long = "check" ) ]
6671 check : bool ,
6772}
6873
@@ -87,7 +92,7 @@ fn execute() -> i32 {
8792 }
8893 } ) ;
8994
90- let opts = Opts :: from_iter ( args) ;
95+ let opts = Opts :: parse_from ( args) ;
9196
9297 let verbosity = match ( opts. verbose , opts. quiet ) {
9398 ( false , false ) => Verbosity :: Normal ,
@@ -204,7 +209,7 @@ fn convert_message_format_to_rustfmt_args(
204209
205210fn print_usage_to_stderr ( reason : & str ) {
206211 eprintln ! ( "{}" , reason) ;
207- let app = Opts :: clap ( ) ;
212+ let app = Opts :: command ( ) ;
208213 app. after_help ( "" )
209214 . write_help ( & mut io:: stderr ( ) )
210215 . expect ( "failed to write to stderr" ) ;
0 commit comments