为Rust CLI工具编写手册页的惯用方法是什么?

Esp*_*n H 13 rust rust-cargo

类Unix操作系统上的CLI应用程序通常提供手册页以供参考.我还没有看到关于如何在Rust生态系统中做到这一点的任何好的指南 - 这样做的惯用方法是什么?

我知道Cargo 构建脚本功能,这是一般的方式吗?如果是,它将如何生成手册页以及如何在不同的操作系统上处理man安装?

cod*_*ons 3

我知道目前最好的方法是使用man crate。这项工作仍在进行中,并且 CLI 工作组正在积极致力于为手册页生成提供更好的支持。

正如自述文件中更详细的描述,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);
}
Run Code Online (Sandbox Code Playgroud)