| Crates.io | clap_usage |
| lib.rs | clap_usage |
| version | 2.0.3 |
| created_at | 2023-08-13 01:34:23.071157+00 |
| updated_at | 2025-01-10 23:40:11.628579+00 |
| description | Library for working with usage specs |
| homepage | https://usage.jdx.dev |
| repository | https://github.com/jdx/usage |
| max_upload_size | |
| id | 943090 |
| size | 41,533 |
Generates usage spec for CLIs written with clap.
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::stdout()).unwrap();
return;
}
// Your CLI code here...
}