initial man page generation

This commit is contained in:
Terts Diepraam
2023-12-08 16:14:15 +01:00
parent 5600b4a4a6
commit 72894a920e
4 changed files with 37 additions and 1 deletions
+1
View File
@@ -11,6 +11,7 @@
"Nonblank",
"nonprinting",
"pico",
"Roff",
"struct",
"uutils",
"xflags"
+1
View File
@@ -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
View File
@@ -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\""),
}
+33
View File
@@ -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()
}