@@ -3,54 +3,55 @@ use clap::crate_version;
33use std:: env;
44use std:: path:: { Path , PathBuf } ;
55
6- use clap:: { App , AppSettings , ArgMatches , SubCommand } ;
6+ use clap:: { arg , ArgMatches , Command } ;
77
88use mdbook:: errors:: Result as Result3 ;
99use mdbook:: MDBook ;
1010
1111fn main ( ) {
12+ let crate_version = format ! ( "v{}" , crate_version!( ) ) ;
1213 env_logger:: Builder :: from_env ( env_logger:: Env :: default ( ) . default_filter_or ( "warn" ) ) . init ( ) ;
13- let d_message = "-d, --dest-dir=[dest-dir]
14- ' The output directory for your book{n}(Defaults to ./book when omitted)'" ;
15- let dir_message = " [dir]
16- ' A directory for your book{n}(Defaults to Current Directory when omitted)'" ;
14+ let d_arg = arg ! ( -d --" dest-dir" < DEST_DIR >
15+ " The output directory for your book{n}(Defaults to ./book when omitted)" ) ;
16+ let dir_arg = arg ! ( [ dir]
17+ " A directory for your book{n}(Defaults to Current Directory when omitted)" ) ;
1718
18- let matches = App :: new ( "rustbook" )
19+ let matches = Command :: new ( "rustbook" )
1920 . about ( "Build a book with mdBook" )
2021 . author ( "Steve Klabnik <steve@steveklabnik.com>" )
21- . version ( & * format ! ( "v{}" , crate_version! ( ) ) )
22- . setting ( AppSettings :: SubcommandRequired )
22+ . version ( & * crate_version)
23+ . subcommand_required ( true )
2324 . subcommand (
24- SubCommand :: with_name ( "build" )
25+ Command :: new ( "build" )
2526 . about ( "Build the book from the markdown files" )
26- . arg_from_usage ( d_message )
27- . arg_from_usage ( dir_message ) ,
27+ . arg ( d_arg )
28+ . arg ( & dir_arg ) ,
2829 )
2930 . subcommand (
30- SubCommand :: with_name ( "test" )
31+ Command :: new ( "test" )
3132 . about ( "Tests that a book's Rust code samples compile" )
32- . arg_from_usage ( dir_message ) ,
33+ . arg ( dir_arg ) ,
3334 )
3435 . get_matches ( ) ;
3536
3637 // Check which subcomamnd the user ran...
3738 match matches. subcommand ( ) {
38- ( "build" , Some ( sub_matches) ) => {
39+ Some ( ( "build" , sub_matches) ) => {
3940 if let Err ( e) = build ( sub_matches) {
4041 handle_error ( e) ;
4142 }
4243 }
43- ( "test" , Some ( sub_matches) ) => {
44+ Some ( ( "test" , sub_matches) ) => {
4445 if let Err ( e) = test ( sub_matches) {
4546 handle_error ( e) ;
4647 }
4748 }
48- ( _ , _ ) => unreachable ! ( ) ,
49+ _ => unreachable ! ( ) ,
4950 } ;
5051}
5152
5253// Build command implementation
53- pub fn build ( args : & ArgMatches < ' _ > ) -> Result3 < ( ) > {
54+ pub fn build ( args : & ArgMatches ) -> Result3 < ( ) > {
5455 let book_dir = get_book_dir ( args) ;
5556 let mut book = load_book ( & book_dir) ?;
5657
@@ -66,13 +67,13 @@ pub fn build(args: &ArgMatches<'_>) -> Result3<()> {
6667 Ok ( ( ) )
6768}
6869
69- fn test ( args : & ArgMatches < ' _ > ) -> Result3 < ( ) > {
70+ fn test ( args : & ArgMatches ) -> Result3 < ( ) > {
7071 let book_dir = get_book_dir ( args) ;
7172 let mut book = load_book ( & book_dir) ?;
7273 book. test ( vec ! [ ] )
7374}
7475
75- fn get_book_dir ( args : & ArgMatches < ' _ > ) -> PathBuf {
76+ fn get_book_dir ( args : & ArgMatches ) -> PathBuf {
7677 if let Some ( dir) = args. value_of ( "dir" ) {
7778 // Check if path is relative from current dir, or absolute...
7879 let p = Path :: new ( dir) ;
0 commit comments