@@ -11,7 +11,14 @@ use mdbook_1::{MDBook as MDBook1};
11
11
use mdbook_1:: errors:: { Result as Result1 } ;
12
12
13
13
use mdbook:: MDBook ;
14
- use mdbook:: errors:: Result ;
14
+ use mdbook:: errors:: { Result as Result3 } ;
15
+
16
+ #[ cfg( all( target_arch = "x86_64" , target_os = "linux" ) ) ]
17
+ use mdbook:: renderer:: RenderContext ;
18
+
19
+ #[ cfg( all( target_arch = "x86_64" , target_os = "linux" ) ) ]
20
+ use mdbook_linkcheck:: { self , errors:: BrokenLinks } ;
21
+ use failure:: Error ;
15
22
16
23
fn main ( ) {
17
24
let d_message = "-d, --dest-dir=[dest-dir]
@@ -31,6 +38,9 @@ fn main() {
31
38
. arg_from_usage ( d_message)
32
39
. arg_from_usage ( dir_message)
33
40
. arg_from_usage ( vers_message) )
41
+ . subcommand ( SubCommand :: with_name ( "linkcheck" )
42
+ . about ( "Run linkcheck with mdBook 3" )
43
+ . arg_from_usage ( dir_message) )
34
44
. get_matches ( ) ;
35
45
36
46
// Check which subcomamnd the user ran...
@@ -64,10 +74,42 @@ fn main() {
64
74
}
65
75
} ;
66
76
} ,
77
+ ( "linkcheck" , Some ( sub_matches) ) => {
78
+ if let Err ( err) = linkcheck ( sub_matches) {
79
+ eprintln ! ( "Error: {}" , err) ;
80
+
81
+ #[ cfg( all( target_arch = "x86_64" , target_os = "linux" ) ) ]
82
+ {
83
+ if let Ok ( broken_links) = err. downcast :: < BrokenLinks > ( ) {
84
+ for cause in broken_links. links ( ) . iter ( ) {
85
+ eprintln ! ( "\t Caused By: {}" , cause) ;
86
+ }
87
+ }
88
+ }
89
+
90
+ :: std:: process:: exit ( 101 ) ;
91
+ }
92
+ } ,
67
93
( _, _) => unreachable ! ( ) ,
68
94
} ;
69
95
}
70
96
97
+ #[ cfg( all( target_arch = "x86_64" , target_os = "linux" ) ) ]
98
+ pub fn linkcheck ( args : & ArgMatches < ' _ > ) -> Result < ( ) , Error > {
99
+ let book_dir = get_book_dir ( args) ;
100
+ let book = MDBook :: load ( & book_dir) . unwrap ( ) ;
101
+ let cfg = book. config ;
102
+ let render_ctx = RenderContext :: new ( & book_dir, book. book , cfg, & book_dir) ;
103
+
104
+ mdbook_linkcheck:: check_links ( & render_ctx)
105
+ }
106
+
107
+ #[ cfg( not( all( target_arch = "x86_64" , target_os = "linux" ) ) ) ]
108
+ pub fn linkcheck ( _args : & ArgMatches < ' _ > ) -> Result < ( ) , Error > {
109
+ println ! ( "mdbook-linkcheck only works on x86_64 linux targets." ) ;
110
+ Ok ( ( ) )
111
+ }
112
+
71
113
// Build command implementation
72
114
pub fn build_1 ( args : & ArgMatches < ' _ > ) -> Result1 < ( ) > {
73
115
let book_dir = get_book_dir ( args) ;
@@ -86,7 +128,7 @@ pub fn build_1(args: &ArgMatches<'_>) -> Result1<()> {
86
128
}
87
129
88
130
// Build command implementation
89
- pub fn build ( args : & ArgMatches < ' _ > ) -> Result < ( ) > {
131
+ pub fn build ( args : & ArgMatches < ' _ > ) -> Result3 < ( ) > {
90
132
let book_dir = get_book_dir ( args) ;
91
133
let mut book = MDBook :: load ( & book_dir) ?;
92
134
0 commit comments