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,27 @@ 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
+ . short ( "t" )
24
+ . long ( "title" )
25
+ . takes_value ( true )
26
+ . help ( "Sets the book title" )
27
+ . required ( false ) ,
28
+ )
29
+ . arg (
30
+ Arg :: with_name ( "gitignore" )
31
+ . short ( "g" )
32
+ . long ( "gitignore" )
33
+ . help ( "Creates a .gitignore" ) ,
34
+ )
21
35
}
22
36
23
37
// Init command implementation
24
38
pub fn execute ( args : & ArgMatches ) -> Result < ( ) > {
25
39
let book_dir = get_book_dir ( args) ;
26
40
let mut builder = MDBook :: init ( & book_dir) ;
27
41
let mut config = config:: Config :: default ( ) ;
28
-
29
42
// If flag `--theme` is present, copy theme to src
30
43
if args. is_present ( "theme" ) {
31
44
let theme_dir = book_dir. join ( "theme" ) ;
@@ -45,13 +58,20 @@ pub fn execute(args: &ArgMatches) -> Result<()> {
45
58
}
46
59
}
47
60
48
- println ! ( "\n Do you want a .gitignore to be created? (y/n)" ) ;
49
-
50
- if confirm ( ) {
61
+ if args. is_present ( "gitignore" ) {
51
62
builder. create_gitignore ( true ) ;
63
+ } else {
64
+ println ! ( "\n Do you want a .gitignore to be created? (y/n)" ) ;
65
+ if confirm ( ) {
66
+ builder. create_gitignore ( true ) ;
67
+ }
52
68
}
53
69
54
- config. book . title = request_book_title ( ) ;
70
+ config. book . title = if args. is_present ( "title" ) {
71
+ args. value_of ( "title" ) . map ( String :: from)
72
+ } else {
73
+ request_book_title ( )
74
+ } ;
55
75
56
76
if let Some ( author) = get_author_name ( ) {
57
77
debug ! ( "Obtained user name from gitconfig: {:?}" , author) ;
0 commit comments