1
1
use crate :: get_book_dir;
2
- use clap:: { App , ArgMatches , SubCommand } ;
2
+ use clap:: { App , Arg , ArgMatches , SubCommand } ;
3
3
use mdbook:: config;
4
4
use mdbook:: errors:: Result ;
5
5
use mdbook:: MDBook ;
@@ -18,14 +18,28 @@ pub fn make_subcommand<'a, 'b>() -> App<'a, 'b> {
18
18
)
19
19
. arg_from_usage ( "--theme 'Copies the default theme into your source folder'" )
20
20
. arg_from_usage ( "--force 'Skips confirmation prompts'" )
21
+ . arg (
22
+ Arg :: with_name ( "title" )
23
+ . long ( "title" )
24
+ . takes_value ( true )
25
+ . help ( "Sets the book title" )
26
+ . required ( false ) ,
27
+ )
28
+ . arg (
29
+ Arg :: with_name ( "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 ) ,
35
+ )
21
36
}
22
37
23
38
// Init command implementation
24
39
pub fn execute ( args : & ArgMatches ) -> Result < ( ) > {
25
40
let book_dir = get_book_dir ( args) ;
26
41
let mut builder = MDBook :: init ( & book_dir) ;
27
42
let mut config = config:: Config :: default ( ) ;
28
-
29
43
// If flag `--theme` is present, copy theme to src
30
44
if args. is_present ( "theme" ) {
31
45
let theme_dir = book_dir. join ( "theme" ) ;
@@ -45,13 +59,23 @@ pub fn execute(args: &ArgMatches) -> Result<()> {
45
59
}
46
60
}
47
61
48
- println ! ( "\n Do you want a .gitignore to be created? (y/n)" ) ;
49
-
50
- if confirm ( ) {
51
- builder. create_gitignore ( true ) ;
62
+ if let Some ( ignore) = args. value_of ( "ignore" ) {
63
+ match ignore {
64
+ "git" => builder. create_gitignore ( true ) ,
65
+ _ => builder. create_gitignore ( false ) ,
66
+ } ;
67
+ } else {
68
+ println ! ( "\n Do you want a .gitignore to be created? (y/n)" ) ;
69
+ if confirm ( ) {
70
+ builder. create_gitignore ( true ) ;
71
+ }
52
72
}
53
73
54
- config. book . title = request_book_title ( ) ;
74
+ config. book . title = if args. is_present ( "title" ) {
75
+ args. value_of ( "title" ) . map ( String :: from)
76
+ } else {
77
+ request_book_title ( )
78
+ } ;
55
79
56
80
if let Some ( author) = get_author_name ( ) {
57
81
debug ! ( "Obtained user name from gitconfig: {:?}" , author) ;
0 commit comments