@@ -8,6 +8,7 @@ use clap::{App, AppSettings, ArgMatches, SubCommand};
8
8
use mdbook:: errors:: Result as Result3 ;
9
9
use mdbook:: MDBook ;
10
10
11
+ #[ cfg( feature = "linkcheck" ) ]
11
12
use failure:: Error ;
12
13
#[ cfg( feature = "linkcheck" ) ]
13
14
use mdbook:: renderer:: RenderContext ;
@@ -52,36 +53,41 @@ fn main() {
52
53
}
53
54
}
54
55
( "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 ) ;
76
79
}
77
- } ;
78
-
79
- if actually_broken {
80
- std:: process:: exit ( 101 ) ;
81
- } else {
82
- std:: process:: exit ( 0 ) ;
83
80
}
84
81
}
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
+ }
85
91
}
86
92
( _, _) => unreachable ! ( ) ,
87
93
} ;
@@ -97,12 +103,6 @@ pub fn linkcheck(args: &ArgMatches<'_>) -> Result<(), Error> {
97
103
mdbook_linkcheck:: check_links ( & render_ctx)
98
104
}
99
105
100
- #[ cfg( not( feature = "linkcheck" ) ) ]
101
- pub fn linkcheck ( _args : & ArgMatches < ' _ > ) -> Result < ( ) , Error > {
102
- println ! ( "mdbook-linkcheck is disabled." ) ;
103
- Ok ( ( ) )
104
- }
105
-
106
106
// Build command implementation
107
107
pub fn build ( args : & ArgMatches < ' _ > ) -> Result3 < ( ) > {
108
108
let book_dir = get_book_dir ( args) ;
0 commit comments