-
Hello, i have trouble mapping non trivial enum like: pub enum ConfigWaypoint {
Datastore(Datastore),
Url(String),
}
// does have impl FromStr...
pub enum Datastore {
Running,
Candidate,
Other(String),
} to a group of args usable in REPL... First step is modelling Clap struct args to be able to create instance of above enum for further processing by sub-crate calls etc.
I stumbled upon several closed issues & discussions from the past mentioning e.g. To map enum to CLAP struct, i tried adding all of its "variants" as standalone pub enum NetconfCommand {
...
#[clap(group(
ArgGroup::new("from")
.required(true)
.args(&["from_datastore", "from_url"]),
))]
CopyConfig {
from_datastore: Option<Datastore>,
from_url: Option<String>,
},
....
} and i end up with runtime panic when i try to run command with no args (i expect help printout with needed args description instead of panic):
The mentioned types do NOT derive or implement Is some part of structure i try to apply incorrect or do i miss some key annotation for my derived Clap structs? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
To check, is your ideal solution #2621? Looks like we have some debug-asserts out of order, making this more confusing. When addressed, it says #!/usr/bin/env -S rust-script --debug
//! ```cargo
//! [dependencies]
//! clap = { path = "../clap", features = ["derive", "debug"] }
//! ```
use clap::Parser;
#[derive(Parser, Debug)]
pub enum Args {
#[clap(group(
clap::ArgGroup::new("from")
.required(true)
.args(&["from-datastore", "from-url"]),
))]
CopyConfig {
from_datastore: Option<String>,
from_url: Option<String>,
},
}
fn main() {
let args = Args::parse();
dbg!(args);
} This was fixed in #3708 but that is behind the |
Beta Was this translation helpful? Give feedback.
To check, is your ideal solution #2621?
Looks like we have some debug-asserts out of order, making this more confusing. When addressed, it says
from_datastore
doesn't exist. This might look weird but the reason is that itsfrom-datastore