Clap: improving the help with value_name
- value_name
By default the help (generated by providing -h) includes the name of the field in angle brackets.
This is usually a repetition of the parameter name in upper case letters.
In many cases this gives good indication of the value the program is expecting, but sometimes you might want to give a better hint.
In such cases you can set the string that will appear inside the angle brackets using the value_name parameter.
- In this example the input field has the default:
INPUTwhile the out field was set toFILENAMEby thevalue_field.
use clap::Parser;
#[derive(Parser, Debug)]
struct Cli {
#[arg(long)]
input: String,
#[arg(long, value_name = "FILENAME")]
output: String,
}
fn main() {
let args = Cli::parse();
println!("{args:?}");
}
Usage: value-name --input <INPUT> --output <FILENAME>
Options:
--input <INPUT>
--output <FILENAME>
-h, --help Print help