@@ -8,6 +8,7 @@ use clap::{App, AppSettings, ArgMatches, SubCommand};
88use mdbook:: errors:: Result as Result3 ;
99use mdbook:: MDBook ;
1010
11+ #[ cfg( feature = "linkcheck" ) ]
1112use failure:: Error ;
1213#[ cfg( feature = "linkcheck" ) ]
1314use mdbook:: renderer:: RenderContext ;
@@ -52,36 +53,41 @@ fn main() {
5253 }
5354 }
5455 ( "linkcheck" , Some ( sub_matches) ) => {
55- if let Err ( err) = linkcheck ( sub_matches) {
56- eprintln ! ( "Error: {}" , err) ;
57-
58- // HACK: ignore timeouts
59- let actually_broken = {
60- #[ cfg( feature = "linkcheck" ) ]
61- {
62- err. downcast :: < BrokenLinks > ( )
63- . map ( |broken_links| {
64- broken_links
65- . links ( )
66- . iter ( )
67- . inspect ( |cause| eprintln ! ( "\t Caused By: {}" , cause) )
68- . any ( |cause| !format ! ( "{}" , cause) . contains ( "timed out" ) )
69- } )
70- . unwrap_or ( false )
71- }
72-
73- #[ cfg( not( feature = "linkcheck" ) ) ]
74- {
75- false
56+ #[ cfg( feature = "linkcheck" ) ]
57+ {
58+ if let Err ( err) = linkcheck ( sub_matches) {
59+ eprintln ! ( "Error: {}" , err) ;
60+
61+ // HACK: ignore timeouts
62+ let actually_broken = err
63+ . downcast :: < BrokenLinks > ( )
64+ . map ( |broken_links| {
65+ broken_links
66+ . links ( )
67+ . iter ( )
68+ . inspect ( |cause| eprintln ! ( "\t Caused By: {}" , cause) )
69+ . fold ( false , |already_broken, cause| {
70+ already_broken || !format ! ( "{}" , cause) . contains ( "timed out" )
71+ } )
72+ } )
73+ . unwrap_or ( false ) ;
74+
75+ if actually_broken {
76+ std:: process:: exit ( 101 ) ;
77+ } else {
78+ std:: process:: exit ( 0 ) ;
7679 }
77- } ;
78-
79- if actually_broken {
80- std:: process:: exit ( 101 ) ;
81- } else {
82- std:: process:: exit ( 0 ) ;
8380 }
8481 }
82+
83+ #[ cfg( not( feature = "linkcheck" ) ) ]
84+ {
85+ // This avoids the `unused_binding` lint.
86+ println ! (
87+ "mdbook-linkcheck is disabled, but arguments were passed: {:?}" ,
88+ sub_matches
89+ ) ;
90+ }
8591 }
8692 ( _, _) => unreachable ! ( ) ,
8793 } ;
@@ -97,12 +103,6 @@ pub fn linkcheck(args: &ArgMatches<'_>) -> Result<(), Error> {
97103 mdbook_linkcheck:: check_links ( & render_ctx)
98104}
99105
100- #[ cfg( not( feature = "linkcheck" ) ) ]
101- pub fn linkcheck ( _args : & ArgMatches < ' _ > ) -> Result < ( ) , Error > {
102- println ! ( "mdbook-linkcheck is disabled." ) ;
103- Ok ( ( ) )
104- }
105-
106106// Build command implementation
107107pub fn build ( args : & ArgMatches < ' _ > ) -> Result3 < ( ) > {
108108 let book_dir = get_book_dir ( args) ;
0 commit comments