Skip to content

Commit 83e37bb

Browse files
committed
uudoc: move tldr.zip warning to build.rs
Move the tldr.zip missing warning from runtime (uudoc.rs) to compile time (build.rs). This ensures the warning is printed only once during the build, instead of 100+ times when make calls uudoc separately for each utility. Fixes #9940
1 parent 81ee8d1 commit 83e37bb

File tree

3 files changed

+25
-26
lines changed

3 files changed

+25
-26
lines changed

build.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// For the full copyright and license information, please view the LICENSE
44
// file that was distributed with this source code.
55

6-
// spell-checker:ignore (vars) krate mangen
6+
// spell-checker:ignore (vars) krate mangen tldr
77

88
use std::env;
99
use std::fs::File;
@@ -19,6 +19,18 @@ pub fn main() {
1919
// See <https://doc.rust-lang.org/cargo/reference/build-scripts.html#change-detection>
2020
println!("cargo:rerun-if-changed=build.rs");
2121

22+
// Check for tldr.zip when building uudoc to warn users once at build time
23+
// instead of repeatedly at runtime for each utility
24+
if env::var("CARGO_FEATURE_UUDOC").is_ok() && !Path::new("docs/tldr.zip").exists() {
25+
println!(
26+
"cargo:warning=No tldr archive found, so the documentation will not include examples."
27+
);
28+
println!("cargo:warning=To include examples, download the tldr archive:");
29+
println!(
30+
"cargo:warning= curl -L https://github.com/tldr-pages/tldr/releases/latest/download/tldr.zip -o docs/tldr.zip"
31+
);
32+
}
33+
2234
if let Ok(profile) = env::var("PROFILE") {
2335
println!("cargo:rustc-cfg=build={profile:?}");
2436
}

src/bin/uudoc.rs

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -133,19 +133,6 @@ fn gen_completions<T: Args>(args: impl Iterator<Item = OsString>, util_map: &Uti
133133
process::exit(0);
134134
}
135135

136-
/// print tldr error
137-
fn print_tldr_error() {
138-
eprintln!("Warning: No tldr archive found, so the documentation will not include examples.");
139-
eprintln!(
140-
"To include examples in the documentation, download the tldr archive and put it in the docs/ folder."
141-
);
142-
eprintln!();
143-
eprintln!(
144-
" curl -L https://github.com/tldr-pages/tldr/releases/latest/download/tldr.zip -o docs/tldr.zip"
145-
);
146-
eprintln!();
147-
}
148-
149136
/// # Errors
150137
/// Returns an error if the writer fails.
151138
#[allow(clippy::too_many_lines)]
@@ -162,9 +149,6 @@ fn main() -> io::Result<()> {
162149
match command {
163150
"manpage" => {
164151
let args_iter = args.into_iter().skip(2);
165-
if tldr_zip.is_none() {
166-
print_tldr_error();
167-
}
168152
gen_manpage(
169153
&mut tldr_zip,
170154
args_iter,
@@ -186,9 +170,6 @@ fn main() -> io::Result<()> {
186170
}
187171
}
188172
}
189-
if tldr_zip.is_none() {
190-
print_tldr_error();
191-
}
192173
let utils = util_map::<Box<dyn Iterator<Item = OsString>>>();
193174
match std::fs::create_dir("docs/src/utils/") {
194175
Err(e) if e.kind() == std::io::ErrorKind::AlreadyExists => Ok(()),

tests/uudoc/mod.rs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,11 @@ fn test_manpage_generation() {
2828
"Command failed with status: {}",
2929
output.status
3030
);
31+
// Note: tldr warning is now printed at build time (in build.rs), not at runtime
3132
assert!(
32-
String::from_utf8_lossy(&output.stderr).contains("Warning: No tldr archive found"),
33-
"stderr should contains tldr alert",
33+
output.stderr.is_empty(),
34+
"stderr should be empty but got: {}",
35+
String::from_utf8_lossy(&output.stderr)
3436
);
3537

3638
let output_str = String::from_utf8_lossy(&output.stdout);
@@ -52,9 +54,11 @@ fn test_manpage_coreutils() {
5254
"Command failed with status: {}",
5355
output.status
5456
);
57+
// Note: tldr warning is now printed at build time (in build.rs), not at runtime
5558
assert!(
56-
String::from_utf8_lossy(&output.stderr).contains("Warning: No tldr archive found"),
57-
"stderr should contains tldr alert",
59+
output.stderr.is_empty(),
60+
"stderr should be empty but got: {}",
61+
String::from_utf8_lossy(&output.stderr)
5862
);
5963

6064
let output_str = String::from_utf8_lossy(&output.stdout);
@@ -123,9 +127,11 @@ fn test_manpage_base64() {
123127
"Command failed with status: {}",
124128
output.status
125129
);
130+
// Note: tldr warning is now printed at build time (in build.rs), not at runtime
126131
assert!(
127-
String::from_utf8_lossy(&output.stderr).contains("Warning: No tldr archive found"),
128-
"stderr should contains tldr alert",
132+
output.stderr.is_empty(),
133+
"stderr should be empty but got: {}",
134+
String::from_utf8_lossy(&output.stderr)
129135
);
130136

131137
let output_str = String::from_utf8_lossy(&output.stdout);

0 commit comments

Comments
 (0)