mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 11:37:44 +00:00
docs: usage and values for options
This commit is contained in:
parent
274459f2ed
commit
ab3623f65a
3 changed files with 45 additions and 11 deletions
|
@ -19,7 +19,7 @@ fn main() {
|
||||||
for (name, (_, app)) in utils {
|
for (name, (_, app)) in utils {
|
||||||
let p = format!("docs/_generated/{}-help.md", name);
|
let p = format!("docs/_generated/{}-help.md", name);
|
||||||
if let Ok(f) = File::create(&p) {
|
if let Ok(f) = File::create(&p) {
|
||||||
write_markdown(f, &mut app());
|
write_markdown(f, &mut app(), name);
|
||||||
println!("Wrote to '{}'", p);
|
println!("Wrote to '{}'", p);
|
||||||
} else {
|
} else {
|
||||||
println!("Error writing to {}", p);
|
println!("Error writing to {}", p);
|
||||||
|
@ -27,8 +27,9 @@ fn main() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn write_markdown(mut w: impl Write, app: &mut App) {
|
fn write_markdown(mut w: impl Write, app: &mut App, name: &str) {
|
||||||
write_version(&mut w, app);
|
write_version(&mut w, app);
|
||||||
|
write_usage(&mut w, app, name);
|
||||||
write_summary(&mut w, app);
|
write_summary(&mut w, app);
|
||||||
write_options(&mut w, app);
|
write_options(&mut w, app);
|
||||||
}
|
}
|
||||||
|
@ -41,6 +42,14 @@ fn write_version(w: &mut impl Write, app: &App) {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn write_usage(w: &mut impl Write, app: &mut App, name: &str) {
|
||||||
|
let _ = writeln!(w, "\n```");
|
||||||
|
let mut usage: String = app.render_usage().lines().nth(1).unwrap().trim().into();
|
||||||
|
usage = usage.replace(app.get_name(), name);
|
||||||
|
let _ = writeln!(w, "{}", usage);
|
||||||
|
let _ = writeln!(w, "```");
|
||||||
|
}
|
||||||
|
|
||||||
fn write_summary(w: &mut impl Write, app: &App) {
|
fn write_summary(w: &mut impl Write, app: &App) {
|
||||||
if let Some(about) = app.get_long_about().or_else(|| app.get_about()) {
|
if let Some(about) = app.get_long_about().or_else(|| app.get_about()) {
|
||||||
let _ = writeln!(w, "{}", about);
|
let _ = writeln!(w, "{}", about);
|
||||||
|
@ -59,18 +68,43 @@ fn write_options(w: &mut impl Write, app: &App) {
|
||||||
} else {
|
} else {
|
||||||
first = false;
|
first = false;
|
||||||
}
|
}
|
||||||
let _ = write!(w, "<code>--{}</code>", l);
|
let _ = write!(w, "<code>");
|
||||||
|
let _ = write!(w, "--{}", l);
|
||||||
|
if let Some(names) = arg.get_value_names() {
|
||||||
|
let _ = write!(
|
||||||
|
w,
|
||||||
|
"={}",
|
||||||
|
names
|
||||||
|
.iter()
|
||||||
|
.map(|x| format!("<{}>", x))
|
||||||
|
.collect::<Vec<_>>()
|
||||||
|
.join(" ")
|
||||||
|
);
|
||||||
|
}
|
||||||
|
let _ = write!(w, "</code>");
|
||||||
}
|
}
|
||||||
for l in arg.get_short_and_visible_aliases().unwrap_or_default() {
|
for s in arg.get_short_and_visible_aliases().unwrap_or_default() {
|
||||||
if !first {
|
if !first {
|
||||||
let _ = write!(w, ", ");
|
let _ = write!(w, ", ");
|
||||||
} else {
|
} else {
|
||||||
first = false;
|
first = false;
|
||||||
}
|
}
|
||||||
let _ = write!(w, "<code>-{}</code>", l);
|
let _ = write!(w, "<code>");
|
||||||
|
let _ = write!(w, "-{}", s);
|
||||||
|
if let Some(names) = arg.get_value_names() {
|
||||||
|
let _ = write!(
|
||||||
|
w,
|
||||||
|
" {}",
|
||||||
|
names
|
||||||
|
.iter()
|
||||||
|
.map(|x| format!("<{}>", x))
|
||||||
|
.collect::<Vec<_>>()
|
||||||
|
.join(" ")
|
||||||
|
);
|
||||||
|
}
|
||||||
|
let _ = write!(w, "</code>");
|
||||||
}
|
}
|
||||||
let _ = writeln!(w, "</dt>");
|
let _ = writeln!(w, "</dt>");
|
||||||
|
|
||||||
let _ = writeln!(w, "<dd>{}</dd>", arg.get_help().unwrap_or_default());
|
let _ = writeln!(w, "<dd>{}</dd>", arg.get_help().unwrap_or_default());
|
||||||
}
|
}
|
||||||
let _ = writeln!(w, "</dl>");
|
let _ = writeln!(w, "</dl>");
|
||||||
|
|
|
@ -19,9 +19,9 @@ use uucore::error::{FromIo, UResult, USimpleError};
|
||||||
use uucore::InvalidEncodingHandling;
|
use uucore::InvalidEncodingHandling;
|
||||||
|
|
||||||
static NAME: &str = "sum";
|
static NAME: &str = "sum";
|
||||||
static USAGE: &str =
|
static USAGE: &str = "sum [OPTION]... [FILE]...";
|
||||||
"[OPTION]... [FILE]...\nWith no FILE, or when FILE is -, read standard input.";
|
static SUMMARY: &str = "Checksum and count the blocks in a file.\n\
|
||||||
static SUMMARY: &str = "Checksum and count the blocks in a file.";
|
With no FILE, or when FILE is -, read standard input.";
|
||||||
|
|
||||||
fn bsd_sum(mut reader: Box<dyn Read>) -> (usize, u16) {
|
fn bsd_sum(mut reader: Box<dyn Read>) -> (usize, u16) {
|
||||||
let mut buf = [0; 1024];
|
let mut buf = [0; 1024];
|
||||||
|
|
|
@ -22,8 +22,8 @@ use uucore::InvalidEncodingHandling;
|
||||||
|
|
||||||
static NAME: &str = "unexpand";
|
static NAME: &str = "unexpand";
|
||||||
static USAGE: &str = "unexpand [OPTION]... [FILE]...";
|
static USAGE: &str = "unexpand [OPTION]... [FILE]...";
|
||||||
static SUMMARY: &str = "Convert blanks in each FILE to tabs, writing to standard output.\n
|
static SUMMARY: &str = "Convert blanks in each FILE to tabs, writing to standard output.\n\
|
||||||
With no FILE, or when FILE is -, read standard input.";
|
With no FILE, or when FILE is -, read standard input.";
|
||||||
|
|
||||||
const DEFAULT_TABSTOP: usize = 8;
|
const DEFAULT_TABSTOP: usize = 8;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue