File tree Expand file tree Collapse file tree 4 files changed +32
-1
lines changed Expand file tree Collapse file tree 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
7676```
7777
7878[ 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<()> {
5656 "git" => builder. create_gitignore ( true ) ,
5757 _ => builder. create_gitignore ( false ) ,
5858 } ;
59- } else {
59+ } else if !args . get_flag ( "force" ) {
6060 println ! ( "\n Do you want a .gitignore to be created? (y/n)" ) ;
6161 if confirm ( ) {
6262 builder. create_gitignore ( true ) ;
@@ -65,6 +65,8 @@ pub fn execute(args: &ArgMatches) -> Result<()> {
6565
6666 config. book . title = if args. contains_id ( "title" ) {
6767 args. get_one :: < String > ( "title" ) . map ( String :: from)
68+ } else if args. get_flag ( "force" ) {
69+ None
6870 } else {
6971 request_book_title ( )
7072 } ;
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 11mod build;
22mod cmd;
3+ mod init;
34mod test;
You can’t perform that action at this time.
0 commit comments