在类Unix操作系统上,CLI应用程序通常提供man页面供参考。我还没有看到任何关于如何在Rust生态系统中做到这一点的好指南 - 这样做的惯用方法是什么?
我知道Cargo build scripts功能,这是否是通常的方法?如果是,它将如何生成man页面,并如何处理不同操作系统上的man安装?
在类Unix操作系统上,CLI应用程序通常提供man页面供参考。我还没有看到任何关于如何在Rust生态系统中做到这一点的好指南 - 这样做的惯用方法是什么?
我知道Cargo build scripts功能,这是否是通常的方法?如果是,它将如何生成man页面,并如何处理不同操作系统上的man安装?
我所知道的目前最佳方法是使用man crate。这仍然是一项正在进行的工作,CLI 工作组正在积极致力于增加更好的man页生成支持。
如 README 中所述,man
可以从类似以下语法的内容生成man页:
use man::prelude::*;
fn main() {
let page = Manual::new("basic")
.about("A basic example")
.author(Author::new("Alice Person").email("alice@person.com"))
.author(Author::new("Bob Human").email("bob@human.com"))
.flag(
Flag::new()
.short("-d")
.long("--debug")
.help("Enable debug mode"),
)
.flag(
Flag::new()
.short("-v")
.long("--verbose")
.help("Enable verbose mode"),
)
.option(
Opt::new("output")
.short("-o")
.long("--output")
.help("The file path to write output to"),
)
.example(
Example::new()
.text("run basic in debug mode")
.command("basic -d")
.output("Debug Mode: basic will print errors to the console")
)
.custom(
Section::new("usage note")
.paragraph("This program will overwrite any file currently stored at the output path")
)
.render();
println!("{}", page);
}