-
Hello! This is a simplified view of a problem I have with another app. I have 2 structs: use clap::*;
#[derive(Debug, Parser)]
struct MyCli {
// other flags
#[arg(short)]
a: bool,
#[command(flatten)]
complex: ComplexArgs,
}
#[derive(Debug)]
struct Complex {
// ...
}
fn transform(args: ComplexArgs) -> Complex {
todo!();
}
#[derive(Debug, Args)]
struct ComplexArgs {
#[arg(short)]
b: bool,
#[arg(short)]
c: bool,
#[arg(short)]
d: bool,
}
fn main() {
let cli = MyCli::parse();
println!("{cli:#?}");
} Currently, I parse into It would be easier for me to have clap perform the transforming, such that #[derive(Debug, Parser)]
struct MyCli {
#[arg(short)]
a: bool,
#[command(flatten)]
// parse a a ComplexArgs and use transform?
complex: Complex,
}
#[derive(Debug)]
// parse as a ComplexArgs and use transform?
struct Complex {
// ...
} This might be a very niche situation, but I might as well try to ask :) |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
I think manually implementing FromArgMatches and Args for my type is the way to go, as described in https://docs.rs/clap/latest/clap/_derive/index.html#flattening-hand-implemented-args-into-a-derived-application |
Beta Was this translation helpful? Give feedback.
I think manually implementing FromArgMatches and Args for my type is the way to go, as described in https://docs.rs/clap/latest/clap/_derive/index.html#flattening-hand-implemented-args-into-a-derived-application