mirror of
https://github.com/uutils/coreutils.git
synced 2026-06-10 15:48:22 -07:00
Merge pull request #7936 from Its-Just-Nans/fix-doc-hashs
fix docs test
This commit is contained in:
+55
-13
@@ -84,6 +84,8 @@ fn gen_manpage<T: Args>(
|
||||
} else {
|
||||
validation::setup_localization_or_exit(utility);
|
||||
let mut cmd = util_map.get(utility).unwrap().1();
|
||||
cmd.set_bin_name(utility.clone());
|
||||
let mut cmd = cmd.display_name(utility);
|
||||
if let Some(zip) = tldr {
|
||||
if let Ok(examples) = write_zip_examples(zip, utility, false) {
|
||||
cmd = cmd.after_help(examples);
|
||||
@@ -274,12 +276,15 @@ fn main() -> io::Result<()> {
|
||||
|
||||
println!("Writing to utils");
|
||||
for (&name, (_, command)) in utils {
|
||||
if name == "[" {
|
||||
continue;
|
||||
}
|
||||
let p = format!("docs/src/utils/{name}.md");
|
||||
let (utils_name, usage_name, command) = match name {
|
||||
"[" => {
|
||||
continue;
|
||||
}
|
||||
n => (n, n, command),
|
||||
};
|
||||
let p = format!("docs/src/utils/{usage_name}.md");
|
||||
|
||||
let fluent = File::open(format!("src/uu/{name}/locales/en-US.ftl"))
|
||||
let fluent = File::open(format!("src/uu/{utils_name}/locales/en-US.ftl"))
|
||||
.and_then(|mut f: File| {
|
||||
let mut s = String::new();
|
||||
f.read_to_string(&mut s)?;
|
||||
@@ -291,21 +296,43 @@ fn main() -> io::Result<()> {
|
||||
MDWriter {
|
||||
w: Box::new(f),
|
||||
command: command(),
|
||||
name,
|
||||
name: usage_name,
|
||||
tldr_zip: &mut tldr_zip,
|
||||
utils_per_platform: &utils_per_platform,
|
||||
fluent,
|
||||
fluent_key: utils_name.to_string(),
|
||||
}
|
||||
.markdown()?;
|
||||
println!("Wrote to '{p}'");
|
||||
} else {
|
||||
println!("Error writing to {p}");
|
||||
}
|
||||
writeln!(summary, "* [{name}](utils/{name}.md)")?;
|
||||
writeln!(summary, "* [{usage_name}](utils/{usage_name}.md)")?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn fix_usage(name: &str, usage: String) -> String {
|
||||
match name {
|
||||
"test" => {
|
||||
// replace to [ but not the first two line
|
||||
usage
|
||||
.lines()
|
||||
.enumerate()
|
||||
.map(|(i, l)| {
|
||||
if i > 1 {
|
||||
l.replace("test", "[")
|
||||
} else {
|
||||
l.to_string()
|
||||
}
|
||||
})
|
||||
.collect::<Vec<_>>()
|
||||
.join("\n")
|
||||
}
|
||||
_ => usage,
|
||||
}
|
||||
}
|
||||
|
||||
struct MDWriter<'a, 'b> {
|
||||
w: Box<dyn Write>,
|
||||
command: Command,
|
||||
@@ -313,6 +340,7 @@ struct MDWriter<'a, 'b> {
|
||||
tldr_zip: &'b mut Option<ZipArchive<File>>,
|
||||
utils_per_platform: &'b HashMap<&'b str, Vec<String>>,
|
||||
fluent: Option<String>,
|
||||
fluent_key: String,
|
||||
}
|
||||
|
||||
impl MDWriter<'_, '_> {
|
||||
@@ -343,9 +371,20 @@ impl MDWriter<'_, '_> {
|
||||
if id.name == key {
|
||||
// Simple text extraction - just concatenate text elements
|
||||
let mut result = String::new();
|
||||
use fluent_syntax::ast::{
|
||||
Expression, InlineExpression,
|
||||
PatternElement::{Placeable, TextElement},
|
||||
};
|
||||
for element in elements {
|
||||
if let fluent_syntax::ast::PatternElement::TextElement { value } = element {
|
||||
result.push_str(&value);
|
||||
if let TextElement { ref value } = element {
|
||||
result.push_str(value);
|
||||
}
|
||||
if let Placeable {
|
||||
expression:
|
||||
Expression::Inline(InlineExpression::StringLiteral { ref value }),
|
||||
} = element
|
||||
{
|
||||
result.push_str(value);
|
||||
}
|
||||
}
|
||||
return Some(result);
|
||||
@@ -403,7 +442,8 @@ impl MDWriter<'_, '_> {
|
||||
/// # Errors
|
||||
/// Returns an error if the writer fails.
|
||||
fn usage(&mut self) -> io::Result<()> {
|
||||
if let Some(usage) = self.extract_fluent_value(&format!("{}-usage", self.name)) {
|
||||
if let Some(usage) = self.extract_fluent_value(&format!("{}-usage", self.fluent_key)) {
|
||||
let usage = fix_usage(self.name, usage);
|
||||
writeln!(self.w, "\n```")?;
|
||||
writeln!(self.w, "{usage}")?;
|
||||
writeln!(self.w, "```")
|
||||
@@ -415,7 +455,7 @@ impl MDWriter<'_, '_> {
|
||||
/// # Errors
|
||||
/// Returns an error if the writer fails.
|
||||
fn about(&mut self) -> io::Result<()> {
|
||||
if let Some(about) = self.extract_fluent_value(&format!("{}-about", self.name)) {
|
||||
if let Some(about) = self.extract_fluent_value(&format!("{}-about", self.fluent_key)) {
|
||||
writeln!(self.w, "{about}")
|
||||
} else {
|
||||
Ok(())
|
||||
@@ -425,7 +465,9 @@ impl MDWriter<'_, '_> {
|
||||
/// # Errors
|
||||
/// Returns an error if the writer fails.
|
||||
fn after_help(&mut self) -> io::Result<()> {
|
||||
if let Some(after_help) = self.extract_fluent_value(&format!("{}-after-help", self.name)) {
|
||||
if let Some(after_help) =
|
||||
self.extract_fluent_value(&format!("{}-after-help", self.fluent_key))
|
||||
{
|
||||
writeln!(self.w, "\n\n{after_help}")
|
||||
} else {
|
||||
Ok(())
|
||||
@@ -498,7 +540,7 @@ impl MDWriter<'_, '_> {
|
||||
writeln!(self.w, "</dt>")?;
|
||||
let help_text = arg.get_help().unwrap_or_default().to_string();
|
||||
// Try to resolve Fluent key if it looks like one, otherwise use as-is
|
||||
let resolved_help = if help_text.starts_with(&format!("{}-help-", self.name)) {
|
||||
let resolved_help = if help_text.starts_with(&format!("{}-help-", self.fluent_key)) {
|
||||
self.extract_fluent_value(&help_text).unwrap_or(help_text)
|
||||
} else {
|
||||
help_text
|
||||
|
||||
Reference in New Issue
Block a user