Announcing clap-markdown — automatically generate Markdown docs for clap command-line tools

69 points Craftable64

Hi everyone,

I've recently been working on several command-line tools, and I wanted an easy way to create online reference documentation describing what each tool can do.

The result was clap-markdown.

clap-markdown makes it easy to generate a CommandLineHelp.md file that can, conventionally, be saved in your project repository and linked to from your README.md file.

The generated Markdown contains all the same helpful documentation content as passing \--help\\ on the command-line, but with nice Markdown formatting.

For some examples of what clap-markdown output looks like, see:

Here's a simple example of what using clap-markdown looks like:

use clap::Parser;

#[derive(Parser)]
struct Cli {
    #[arg(long, hide = true)]
    markdown_help: bool,
}

fn main() {
    let args = Cli::parse();

    // Invoked as: `$ my-app --markdown-help`
    if args.markdown_help {
        clap_markdown::print_help_markdown::<Cli>();
    }
}

With the program above, you can easily save an up-to-date, auto-generated Markdown version of your command documentation by executing the following command:

$ cargo run -- --markdown-help > docs/CommandLineHelp.md

This is my first time sharing a crate on /r/rust, so all feedback or suggestions are appreciated!

Note: This project has no relation to the clap-md project, which seems to have been an earlier attempt at a tool like this.