1
1
use crate :: get_book_dir;
2
- use clap:: { arg, App , Arg , ArgMatches } ;
2
+ use clap:: { arg, ArgMatches , Command as ClapCommand } ;
3
3
use mdbook:: config;
4
4
use mdbook:: errors:: Result ;
5
5
use mdbook:: MDBook ;
@@ -8,30 +8,22 @@ use std::io::Write;
8
8
use std:: process:: Command ;
9
9
10
10
// Create clap subcommand arguments
11
- pub fn make_subcommand < ' help > ( ) -> App < ' help > {
12
- App :: new ( "init" )
11
+ pub fn make_subcommand ( ) -> ClapCommand {
12
+ ClapCommand :: new ( "init" )
13
13
. about ( "Creates the boilerplate structure and files for a new book" )
14
- // the {n} denotes a newline which will properly aligned in all help messages
15
- . arg ( arg ! ( [ dir]
16
- "Directory to create the book in{n}\
17
- (Defaults to the Current Directory when omitted)"
18
- ) )
19
- . arg ( arg ! ( --theme "Copies the default theme into your source folder" ) )
20
- . arg ( arg ! ( --force "Skips confirmation prompts" ) )
21
14
. arg (
22
- Arg :: new ( "title" )
23
- . long ( "title" )
24
- . takes_value ( true )
25
- . help ( "Sets the book title" )
26
- . required ( false ) ,
15
+ arg ! ( [ dir ]
16
+ "Directory to create the book in \n \
17
+ (Defaults to the current directory when omitted)"
18
+ )
19
+ . value_parser ( clap :: value_parser! ( std :: path :: PathBuf ) ) ,
27
20
)
21
+ . arg ( arg ! ( --theme "Copies the default theme into your source folder" ) )
22
+ . arg ( arg ! ( --force "Skips confirmation prompts" ) )
23
+ . arg ( arg ! ( --title <title> "Sets the book title" ) )
28
24
. arg (
29
- Arg :: new ( "ignore" )
30
- . long ( "ignore" )
31
- . takes_value ( true )
32
- . possible_values ( & [ "none" , "git" ] )
33
- . help ( "Creates a VCS ignore file (i.e. .gitignore)" )
34
- . required ( false ) ,
25
+ arg ! ( --ignore <ignore> "Creates a VCS ignore file (i.e. .gitignore)" )
26
+ . value_parser ( [ "none" , "git" ] ) ,
35
27
)
36
28
}
37
29
@@ -41,12 +33,12 @@ pub fn execute(args: &ArgMatches) -> Result<()> {
41
33
let mut builder = MDBook :: init ( & book_dir) ;
42
34
let mut config = config:: Config :: default ( ) ;
43
35
// If flag `--theme` is present, copy theme to src
44
- if args. is_present ( "theme" ) {
36
+ if args. get_flag ( "theme" ) {
45
37
let theme_dir = book_dir. join ( "theme" ) ;
46
38
println ! ( ) ;
47
39
println ! ( "Copying the default theme to {}" , theme_dir. display( ) ) ;
48
40
// Skip this if `--force` is present
49
- if !args. is_present ( "force" ) && theme_dir. exists ( ) {
41
+ if !args. get_flag ( "force" ) && theme_dir. exists ( ) {
50
42
println ! ( "This could potentially overwrite files already present in that directory." ) ;
51
43
print ! ( "\n Are you sure you want to continue? (y/n) " ) ;
52
44
@@ -59,7 +51,7 @@ pub fn execute(args: &ArgMatches) -> Result<()> {
59
51
}
60
52
}
61
53
62
- if let Some ( ignore) = args. value_of ( "ignore" ) {
54
+ if let Some ( ignore) = args. get_one :: < String > ( "ignore" ) . map ( |s| s . as_str ( ) ) {
63
55
match ignore {
64
56
"git" => builder. create_gitignore ( true ) ,
65
57
_ => builder. create_gitignore ( false ) ,
@@ -71,8 +63,8 @@ pub fn execute(args: &ArgMatches) -> Result<()> {
71
63
}
72
64
}
73
65
74
- config. book . title = if args. is_present ( "title" ) {
75
- args. value_of ( "title" ) . map ( String :: from)
66
+ config. book . title = if args. contains_id ( "title" ) {
67
+ args. get_one :: < String > ( "title" ) . map ( String :: from)
76
68
} else {
77
69
request_book_title ( )
78
70
} ;
0 commit comments