11use crate :: get_book_dir;
2- use clap:: { arg, App , Arg , ArgMatches } ;
2+ use clap:: { arg, ArgMatches , Command as ClapCommand } ;
33use mdbook:: config;
44use mdbook:: errors:: Result ;
55use mdbook:: MDBook ;
@@ -8,30 +8,22 @@ use std::io::Write;
88use std:: process:: Command ;
99
1010// 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" )
1313 . 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" ) )
2114 . 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 ) ) ,
2720 )
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" ) )
2824 . 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" ] ) ,
3527 )
3628}
3729
@@ -41,12 +33,12 @@ pub fn execute(args: &ArgMatches) -> Result<()> {
4133 let mut builder = MDBook :: init ( & book_dir) ;
4234 let mut config = config:: Config :: default ( ) ;
4335 // If flag `--theme` is present, copy theme to src
44- if args. is_present ( "theme" ) {
36+ if args. get_flag ( "theme" ) {
4537 let theme_dir = book_dir. join ( "theme" ) ;
4638 println ! ( ) ;
4739 println ! ( "Copying the default theme to {}" , theme_dir. display( ) ) ;
4840 // Skip this if `--force` is present
49- if !args. is_present ( "force" ) && theme_dir. exists ( ) {
41+ if !args. get_flag ( "force" ) && theme_dir. exists ( ) {
5042 println ! ( "This could potentially overwrite files already present in that directory." ) ;
5143 print ! ( "\n Are you sure you want to continue? (y/n) " ) ;
5244
@@ -59,7 +51,7 @@ pub fn execute(args: &ArgMatches) -> Result<()> {
5951 }
6052 }
6153
62- if let Some ( ignore) = args. value_of ( "ignore" ) {
54+ if let Some ( ignore) = args. get_one :: < String > ( "ignore" ) . map ( |s| s . as_str ( ) ) {
6355 match ignore {
6456 "git" => builder. create_gitignore ( true ) ,
6557 _ => builder. create_gitignore ( false ) ,
@@ -71,8 +63,8 @@ pub fn execute(args: &ArgMatches) -> Result<()> {
7163 }
7264 }
7365
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)
7668 } else {
7769 request_book_title ( )
7870 } ;
0 commit comments