File tree 4 files changed +32
-1
lines changed
4 files changed +32
-1
lines changed Original file line number Diff line number Diff line change @@ -76,3 +76,7 @@ mdbook init --ignore=git
76
76
```
77
77
78
78
[ building ] : build.md
79
+
80
+ #### --force
81
+
82
+ Skip the prompts to create a ` .gitignore ` and for the title for the book.
Original file line number Diff line number Diff line change @@ -56,7 +56,7 @@ pub fn execute(args: &ArgMatches) -> Result<()> {
56
56
"git" => builder. create_gitignore ( true ) ,
57
57
_ => builder. create_gitignore ( false ) ,
58
58
} ;
59
- } else {
59
+ } else if !args . get_flag ( "force" ) {
60
60
println ! ( "\n Do you want a .gitignore to be created? (y/n)" ) ;
61
61
if confirm ( ) {
62
62
builder. create_gitignore ( true ) ;
@@ -65,6 +65,8 @@ pub fn execute(args: &ArgMatches) -> Result<()> {
65
65
66
66
config. book . title = if args. contains_id ( "title" ) {
67
67
args. get_one :: < String > ( "title" ) . map ( String :: from)
68
+ } else if args. get_flag ( "force" ) {
69
+ None
68
70
} else {
69
71
request_book_title ( )
70
72
} ;
Original file line number Diff line number Diff line change
1
+ use crate :: cli:: cmd:: mdbook_cmd;
2
+ use crate :: dummy_book:: DummyBook ;
3
+
4
+ use mdbook:: config:: Config ;
5
+
6
+ /// Run `mdbook init` with `--force` to skip the confirmation prompts
7
+ #[ test]
8
+ fn base_mdbook_init_can_skip_confirmation_prompts ( ) {
9
+ let temp = DummyBook :: new ( ) . build ( ) . unwrap ( ) ;
10
+
11
+ // doesn't exist before
12
+ assert ! ( !temp. path( ) . join( "book" ) . exists( ) ) ;
13
+
14
+ let mut cmd = mdbook_cmd ( ) ;
15
+ cmd. args ( [ "init" , "--force" ] ) . current_dir ( temp. path ( ) ) ;
16
+ cmd. assert ( )
17
+ . success ( )
18
+ . stdout ( predicates:: str:: contains ( "\n All done, no errors...\n " ) ) ;
19
+
20
+ let config = Config :: from_disk ( temp. path ( ) . join ( "book.toml" ) ) . unwrap ( ) ;
21
+ assert_eq ! ( config. book. title, None ) ;
22
+
23
+ assert ! ( !temp. path( ) . join( ".gitignore" ) . exists( ) ) ;
24
+ }
Original file line number Diff line number Diff line change 1
1
mod build;
2
2
mod cmd;
3
+ mod init;
3
4
mod test;
You can’t perform that action at this time.
0 commit comments