Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// For the full copyright and license information, please view the LICENSE
// file that was distributed with this source code.

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

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

// Check for tldr.zip when building uudoc to warn users once at build time
// instead of repeatedly at runtime for each utility
if env::var("CARGO_FEATURE_UUDOC").is_ok() && !Path::new("docs/tldr.zip").exists() {
println!(
"cargo:warning=No tldr archive found, so the documentation will not include examples."
);
println!("cargo:warning=To include examples, download the tldr archive:");
println!(
"cargo:warning= curl -L https://github.com/tldr-pages/tldr/releases/latest/download/tldr.zip -o docs/tldr.zip"
);
}

if let Ok(profile) = env::var("PROFILE") {
println!("cargo:rustc-cfg=build={profile:?}");
}
Expand Down
19 changes: 0 additions & 19 deletions src/bin/uudoc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,19 +133,6 @@ fn gen_completions<T: Args>(args: impl Iterator<Item = OsString>, util_map: &Uti
process::exit(0);
}

/// print tldr error
fn print_tldr_error() {
eprintln!("Warning: No tldr archive found, so the documentation will not include examples.");
eprintln!(
"To include examples in the documentation, download the tldr archive and put it in the docs/ folder."
);
eprintln!();
eprintln!(
" curl -L https://github.com/tldr-pages/tldr/releases/latest/download/tldr.zip -o docs/tldr.zip"
);
eprintln!();
}

/// # Errors
/// Returns an error if the writer fails.
#[allow(clippy::too_many_lines)]
Expand All @@ -162,9 +149,6 @@ fn main() -> io::Result<()> {
match command {
"manpage" => {
let args_iter = args.into_iter().skip(2);
if tldr_zip.is_none() {
print_tldr_error();
}
gen_manpage(
&mut tldr_zip,
args_iter,
Expand All @@ -186,9 +170,6 @@ fn main() -> io::Result<()> {
}
}
}
if tldr_zip.is_none() {
print_tldr_error();
}
let utils = util_map::<Box<dyn Iterator<Item = OsString>>>();
match std::fs::create_dir("docs/src/utils/") {
Err(e) if e.kind() == std::io::ErrorKind::AlreadyExists => Ok(()),
Expand Down
18 changes: 12 additions & 6 deletions tests/uudoc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,11 @@ fn test_manpage_generation() {
"Command failed with status: {}",
output.status
);
// Note: tldr warning is now printed at build time (in build.rs), not at runtime
assert!(
String::from_utf8_lossy(&output.stderr).contains("Warning: No tldr archive found"),
"stderr should contains tldr alert",
output.stderr.is_empty(),
"stderr should be empty but got: {}",
String::from_utf8_lossy(&output.stderr)
);

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

let output_str = String::from_utf8_lossy(&output.stdout);
Expand Down Expand Up @@ -123,9 +127,11 @@ fn test_manpage_base64() {
"Command failed with status: {}",
output.status
);
// Note: tldr warning is now printed at build time (in build.rs), not at runtime
assert!(
String::from_utf8_lossy(&output.stderr).contains("Warning: No tldr archive found"),
"stderr should contains tldr alert",
output.stderr.is_empty(),
"stderr should be empty but got: {}",
String::from_utf8_lossy(&output.stderr)
);

let output_str = String::from_utf8_lossy(&output.stdout);
Expand Down
Loading