3 releases (1 stable)

1.0.0 Dec 9, 2024
0.2.0 Nov 4, 2024
0.1.0 Aug 13, 2023

#711 in Development tools

Download history 3/week @ 2024-09-23 4/week @ 2024-10-14 269/week @ 2024-11-04 239/week @ 2024-11-11 66/week @ 2024-11-18 19/week @ 2024-11-25 16/week @ 2024-12-02 315/week @ 2024-12-09

418 downloads per month
Used in 3 crates

MIT license

145KB
4K SLoC

clap_usage

Generates usage spec for CLIs written with clap.

Usage

use clap::{arg, Command, ValueHint};
use clap_usage::generate;
use std::io::BufWriter;

fn build_cli() -> Command {
    Command::new("example")
        .arg(arg!(--file <FILE> "some input file").value_hint(ValueHint::AnyPath))
        .arg(arg!(--usage))
}

fn main() {
    let matches = build_cli().get_matches();

    if matches.get_flag("usage") {
        let mut cmd = build_cli();
        eprintln!("Generating usage spec...");
        clap_usage::generate(&mut cmd, "example", &mut std::io::stderr()).unwrap();
        return;
    }

    // Your CLI code here...
}

Dependencies

~9–36MB
~557K SLoC