I want to have an argument that can be a number or a string. Not sure how to achieve this besides implementing FromStr myself. It seems like a simple use-case to handle, not sure what macros to use.
Here, I want the testapp_id to be a number or a string.
I'm aiming for the usage to be like this:
cargo run -- testapps status 3 or cargo run -- testapps status app4
#[derive(Parser, Debug)]
#[clap(author,version,about)]
enum Submodules {
#[clap(subcommand)]
Testapps(TestappsCommands)
}
#[derive(Subcommand, Debug)]
enum TestappsCommands {
List,
Status {
#[clap(flatten)]
testapp_id: NumberOrString
},
}
#[derive(Debug)]
enum NumberOrString {
Number(u32),
Str(String),
}
I was thinking flatten is what I could use for this but it's still complaining about missing implementation of FromStr .
It works fine if I use only u32 or String type for testapp_id , why not both?