Merge branch 'main' into fix-doc-hashs

This commit is contained in:
n4n5
2026-01-31 10:39:22 -07:00
462 changed files with 18031 additions and 7421 deletions
+13 -21
View File
@@ -5,6 +5,7 @@
use clap::Command;
use coreutils::validation;
use itertools::Itertools as _;
use std::cmp;
use std::ffi::OsString;
use std::io::{self, Write};
@@ -28,10 +29,7 @@ fn usage<T>(utils: &UtilityMap<T>, name: &str) {
println!("Options:");
println!(" --list lists all defined functions, one per row\n");
println!("Currently defined functions:\n");
#[allow(clippy::map_clone)]
let mut utils: Vec<&str> = utils.keys().map(|&s| s).collect();
utils.sort_unstable();
let display_list = utils.join(", ");
let display_list = utils.keys().copied().sorted_unstable().join(", ");
let width = cmp::min(textwrap::termwidth(), 100) - 4 * 2; // (opinion/heuristic) max 100 chars wide with 4 character side indentions
println!(
"{}",
@@ -52,24 +50,18 @@ fn main() {
process::exit(0);
});
// binary name equals util name?
if let Some(&(uumain, _)) = utils.get(binary_as_util) {
validation::setup_localization_or_exit(binary_as_util);
process::exit(uumain(vec![binary.into()].into_iter().chain(args)));
}
// binary name ends with util name?
let matched_util = utils
.keys()
.filter(|&&u| binary_as_util.ends_with(u) && !binary_as_util.ends_with("coreutils"))
.max_by_key(|u| u.len()); //Prefer stty more than tty. coreutils is not ls
// binary name equals prefixed util name?
// * prefix/stem may be any string ending in a non-alphanumeric character
// For example, if the binary is named `uu_test`, it will match `test` as a utility.
let util_name =
if let Some(util) = validation::find_prefixed_util(binary_as_util, utils.keys().copied()) {
// prefixed util => replace 0th (aka, executable name) argument
Some(OsString::from(util))
} else {
// unmatched binary name => regard as multi-binary container and advance argument list
uucore::set_utility_is_second_arg();
args.next()
};
let util_name = if let Some(&util) = matched_util {
Some(OsString::from(util))
} else {
uucore::set_utility_is_second_arg();
args.next()
};
// 0th argument equals util name?
if let Some(util_os) = util_name {
+4 -21
View File
@@ -135,19 +135,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)]
@@ -164,9 +151,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,
@@ -188,9 +172,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(()),
@@ -536,7 +517,9 @@ impl MDWriter<'_, '_> {
/// # Errors
/// Returns an error if the writer fails.
fn options(&mut self) -> io::Result<()> {
writeln!(self.w, "<h2>Options</h2>")?;
writeln!(self.w)?;
writeln!(self.w, "## Options")?;
writeln!(self.w)?;
write!(self.w, "<dl>")?;
for arg in self.command.get_arguments() {
write!(self.w, "<dt>")?;
@@ -647,7 +630,7 @@ fn format_examples(content: String, output_markdown: bool) -> Result<String, std
use std::fmt::Write;
let mut s = String::new();
writeln!(s)?;
writeln!(s, "Examples")?;
writeln!(s, "## Examples")?;
writeln!(s)?;
for line in content.lines().skip_while(|l| !l.starts_with('-')) {
if let Some(l) = line.strip_prefix("- ") {