I have this example:
use clap::Parser;
#[derive(clap::ValueEnum, Clone, Debug)]
enum InfoType {
All,
Headers,
Metadata,
}
#[derive(Parser, Debug)]
#[clap(version)]
#[clap(about = "Prints out metadata for each file")]
struct Args {
#[clap(long)]
#[clap(help = "What to print")]
#[clap(value_enum, default_value_t=InfoType::All)]
info: InfoType,
#[clap(value_parser, required(true))]
#[clap(help = "file(s)")]
files: Vec<String>,
}
fn main() {
let args = Args::parse();
println!("args {:?}", args)
}
Here the cli interface becomes almost but not quite what I want
USAGE:
my_test [OPTIONS] <FILES>...
ARGS:
<FILES>... file(s)
OPTIONS:
-h, --help Print help information
--info <INFO> What to print [default: all] [possible values: all, headers, metadata]
-V, --version Print version information
Now this can be run as e.g.
my_test /path/file1 /path/file2 # enables the --info all by default
my_test --info headers /path/file1 /path/file2
What I would like instead is to have the --info <INFO>
flag just as --metadata
, --all
etc. So I can run
my_test /path/file1 /path/file2 # enables the --all all by default
my_test --info /path/file1 /path/file2
But still parsing those flags to the same enum variable - how would I set up this with clap ?