Skip to content

Commit bad8147

Browse files
committed
fix reviewer comments
1 parent 3f6db84 commit bad8147

File tree

1 file changed

+33
-33
lines changed

1 file changed

+33
-33
lines changed

src/tools/rustbook/src/main.rs

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use clap::{App, AppSettings, ArgMatches, SubCommand};
88
use mdbook::errors::Result as Result3;
99
use mdbook::MDBook;
1010

11+
#[cfg(feature = "linkcheck")]
1112
use failure::Error;
1213
#[cfg(feature = "linkcheck")]
1314
use 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!("\tCaused 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!("\tCaused 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
107107
pub fn build(args: &ArgMatches<'_>) -> Result3<()> {
108108
let book_dir = get_book_dir(args);

0 commit comments

Comments
 (0)