@@ -3,54 +3,55 @@ use clap::crate_version;
3
3
use std:: env;
4
4
use std:: path:: { Path , PathBuf } ;
5
5
6
- use clap:: { App , AppSettings , ArgMatches , SubCommand } ;
6
+ use clap:: { arg , ArgMatches , Command } ;
7
7
8
8
use mdbook:: errors:: Result as Result3 ;
9
9
use mdbook:: MDBook ;
10
10
11
11
fn main ( ) {
12
+ let crate_version = format ! ( "v{}" , crate_version!( ) ) ;
12
13
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)" ) ;
17
18
18
- let matches = App :: new ( "rustbook" )
19
+ let matches = Command :: new ( "rustbook" )
19
20
. about ( "Build a book with mdBook" )
20
21
. author ( "Steve Klabnik <[email protected] >" )
21
- . version ( & * format ! ( "v{}" , crate_version! ( ) ) )
22
- . setting ( AppSettings :: SubcommandRequired )
22
+ . version ( & * crate_version)
23
+ . subcommand_required ( true )
23
24
. subcommand (
24
- SubCommand :: with_name ( "build" )
25
+ Command :: new ( "build" )
25
26
. 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 ) ,
28
29
)
29
30
. subcommand (
30
- SubCommand :: with_name ( "test" )
31
+ Command :: new ( "test" )
31
32
. about ( "Tests that a book's Rust code samples compile" )
32
- . arg_from_usage ( dir_message ) ,
33
+ . arg ( dir_arg ) ,
33
34
)
34
35
. get_matches ( ) ;
35
36
36
37
// Check which subcomamnd the user ran...
37
38
match matches. subcommand ( ) {
38
- ( "build" , Some ( sub_matches) ) => {
39
+ Some ( ( "build" , sub_matches) ) => {
39
40
if let Err ( e) = build ( sub_matches) {
40
41
handle_error ( e) ;
41
42
}
42
43
}
43
- ( "test" , Some ( sub_matches) ) => {
44
+ Some ( ( "test" , sub_matches) ) => {
44
45
if let Err ( e) = test ( sub_matches) {
45
46
handle_error ( e) ;
46
47
}
47
48
}
48
- ( _ , _ ) => unreachable ! ( ) ,
49
+ _ => unreachable ! ( ) ,
49
50
} ;
50
51
}
51
52
52
53
// Build command implementation
53
- pub fn build ( args : & ArgMatches < ' _ > ) -> Result3 < ( ) > {
54
+ pub fn build ( args : & ArgMatches ) -> Result3 < ( ) > {
54
55
let book_dir = get_book_dir ( args) ;
55
56
let mut book = load_book ( & book_dir) ?;
56
57
@@ -66,13 +67,13 @@ pub fn build(args: &ArgMatches<'_>) -> Result3<()> {
66
67
Ok ( ( ) )
67
68
}
68
69
69
- fn test ( args : & ArgMatches < ' _ > ) -> Result3 < ( ) > {
70
+ fn test ( args : & ArgMatches ) -> Result3 < ( ) > {
70
71
let book_dir = get_book_dir ( args) ;
71
72
let mut book = load_book ( & book_dir) ?;
72
73
book. test ( vec ! [ ] )
73
74
}
74
75
75
- fn get_book_dir ( args : & ArgMatches < ' _ > ) -> PathBuf {
76
+ fn get_book_dir ( args : & ArgMatches ) -> PathBuf {
76
77
if let Some ( dir) = args. value_of ( "dir" ) {
77
78
// Check if path is relative from current dir, or absolute...
78
79
let p = Path :: new ( dir) ;
0 commit comments