You've already forked uutils-args
mirror of
https://github.com/uutils/uutils-args.git
synced 2026-06-10 16:13:08 -07:00
initial man page generation
This commit is contained in:
Vendored
+1
@@ -11,6 +11,7 @@
|
||||
"Nonblank",
|
||||
"nonprinting",
|
||||
"pico",
|
||||
"Roff",
|
||||
"struct",
|
||||
"uutils",
|
||||
"xflags"
|
||||
|
||||
@@ -8,3 +8,4 @@ license = "MIT"
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
roff = "0.2.1"
|
||||
+2
-1
@@ -2,6 +2,7 @@
|
||||
// file that was distributed with this source code.
|
||||
|
||||
mod fish;
|
||||
mod man;
|
||||
mod md;
|
||||
mod zsh;
|
||||
|
||||
@@ -39,7 +40,7 @@ pub fn render(c: &Command, shell: &str) -> String {
|
||||
"md" => md::render(c),
|
||||
"fish" => fish::render(c),
|
||||
"zsh" => zsh::render(c),
|
||||
"man" => panic!("manpages are not implemented yet"),
|
||||
"man" => man::render(c),
|
||||
"sh" | "bash" | "csh" | "elvish" | "powershell" => panic!("shell '{shell}' completion is not implemented yet!"),
|
||||
_ => panic!("unknown option '{shell}'! Expected one of: \"md\", \"fish\", \"zsh\", \"man\", \"sh\", \"bash\", \"csh\", \"elvish\", \"powershell\""),
|
||||
}
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
use crate::Command;
|
||||
use roff::{bold, roman, Roff};
|
||||
|
||||
pub fn render(c: &Command) -> String {
|
||||
let mut page = Roff::new();
|
||||
page.control("TH", [&c.name.to_uppercase(), "1"]);
|
||||
page.control("SH", ["NAME"]);
|
||||
page.text([roman(&c.name)]);
|
||||
page.control("SH", ["DESCRIPTION"]);
|
||||
page.text([roman(&c.summary)]);
|
||||
page.control("SH", ["OPTIONS"]);
|
||||
|
||||
for arg in &c.args {
|
||||
page.control("TP", []);
|
||||
|
||||
let mut flags = Vec::new();
|
||||
for l in &arg.long {
|
||||
if !flags.is_empty() {
|
||||
flags.push(roman(", "));
|
||||
}
|
||||
flags.push(bold(format!("--{l}")));
|
||||
}
|
||||
for s in &arg.short {
|
||||
if !flags.is_empty() {
|
||||
flags.push(roman(", "));
|
||||
}
|
||||
flags.push(bold(format!("-{s}")));
|
||||
}
|
||||
page.text(flags);
|
||||
page.text([roman(&arg.help)]);
|
||||
}
|
||||
page.render()
|
||||
}
|
||||
Reference in New Issue
Block a user