No valid flag combinations? #1799
-
I have a project using
However, for both of these, no possible type+option pairs produced anything other than an error message, and I can't for the life of me figure out why. And yes, I did test each of them - see the following log files. I'm betting there's some obvious fix that I'm missing and have been missing for the past many hours, but I'm probably just so stuck in a rut that I can't see it. |
Beta Was this translation helpful? Give feedback.
Replies: 8 comments 3 replies
-
Can you minimize your issue and post the code example with cli results here please? Maybe try the example with 2 worktypes and 2 options? |
Beta Was this translation helpful? Give feedback.
-
Alright, I limited it to use clap::{App, Arg, ArgGroup, SubCommand};
fn main() {
match request_from_args() {
Ok(()) => println!("Success!"),
Err(e) => println!("{}", e),
}
}
fn request_from_args() -> Result<(), String> {
App::new("primenet-rs")
.subcommand(
SubCommand::with_name("p95")
.arg(
Arg::with_name("p95-trial-factoring")
.visible_alias("p95-tf")
.long("p95-trial-factoring")
)
.arg(
Arg::with_name("p95-p1-factoring")
.visible_alias("p95-p1")
.long("p95-p1-factoring")
)
.group(
ArgGroup::with_name("p95-worktypes")
.args(&["p95-trial-factoring", "p95-p1-factoring"])
.multiple(false)
.required(true),
)
.arg(
Arg::with_name("p95-factoring-lmh")
.long("p95-factoring-lmh")
.conflicts_with_all(&["p95-p1-factoring"]),
)
.arg(
Arg::with_name("p95-factoring-trial-sieve")
.long("p95-factoring-trial-sieve")
.conflicts_with_all(&["p95-p1-factoring"]),
)
.group(
ArgGroup::with_name("p95-workopts")
.args(&["p95-factoring-lmh", "p95-factoring-trial-sieve"])
.multiple(false)
.required(true),
)
).get_matches_safe().map(|_| ()).map_err(|e| format!("{}", e))
} The log for it: groups-small.log use clap::{App, Arg, SubCommand};
fn main() {
match request_from_args() {
Ok(()) => println!("Success!"),
Err(e) => println!("{}", e),
}
}
const P95TF_LIST: [&str; 1] = [
"p95-p1-factoring",
];
const P95P1F_LIST: [&str; 3] = [
"p95-trial-factoring",
"p95-factoring-lmh",
"p95-factoring-trial-sieve",
];
const P95FLMH_LIST: [&str; 2] = [
"p95-p1-factoring",
"p95-factoring-trial-sieve",
];
const P95FTS_LIST: [&str; 2] = [
"p95-p1-factoring",
"p95-factoring-lmh",
];
fn request_from_args() -> Result<(), String> {
App::new("primenet-rs")
.subcommand(
SubCommand::with_name("p95")
.arg(
Arg::with_name("p95-trial-factoring")
.visible_alias("p95-tf")
.long("p95-trial-factoring")
.help("Request trial factoring work from Primenet")
.required_unless_one(&P95TF_LIST)
.conflicts_with_all(&P95TF_LIST),
)
.arg(
Arg::with_name("p95-p1-factoring")
.visible_alias("p95-p1")
.long("p95-p1-factoring")
.help("Request P-1 factoring work from Primenet")
.required_unless_one(&P95P1F_LIST)
.conflicts_with_all(&P95P1F_LIST),
)
.arg(
Arg::with_name("p95-factoring-lmh")
.visible_alias("p95-flmh")
.long("p95-factoring-lmh")
.help("Request factoring LFH work from Primenet")
.required_unless_one(&P95FLMH_LIST)
.conflicts_with_all(&P95FLMH_LIST),
)
.arg(
Arg::with_name("p95-factoring-trial-sieve")
.visible_alias("p95-fts")
.long("p95-factoring-trial-sieve")
.help("Request factoring trail (sieve) work from Primenet")
.required_unless_one(&P95FTS_LIST)
.conflicts_with_all(&P95FTS_LIST),
)
).get_matches_safe().map(|_| ()).map_err(|e| format!("{}", e))
} The log for it: lists-small.log It appears to me that the issue only appears in the larger groups, since the two pairs of type+opt that should work did work in these smaller examples. Edit: Removed unnecessary |
Beta Was this translation helpful? Give feedback.
-
Finally got a smaller working example that produces the unexpected behaviour of no working type+opt combos. This one has three types and four opts: use clap::{App, Arg, ArgGroup, SubCommand};
fn main() {
match request_from_args() {
Ok(()) => println!("Success!"),
Err(e) => println!("{}", e),
}
}
fn request_from_args() -> Result<(), String> {
App::new("primenet-rs")
.subcommand(
SubCommand::with_name("p95")
.arg(
Arg::with_name("p95-trial-factoring")
.visible_alias("p95-tf")
.long("p95-trial-factoring")
)
.arg(
Arg::with_name("p95-p1-factoring")
.visible_alias("p95-p1")
.long("p95-p1-factoring")
)
.arg(
Arg::with_name("p95-optimal-p1-factoring")
.visible_alias("p95-op1")
.long("p95-optimal-p1-factoring")
)
.group(
ArgGroup::with_name("p95-worktypes")
.args(&[
"p95-trial-factoring",
"p95-p1-factoring",
"p95-optimal-p1-factoring",
])
.multiple(false)
.required(true),
)
.arg(
Arg::with_name("p95-what-makes-most-sense")
.long("p95-what-makes-most-sense")
)
.arg(
Arg::with_name("p95-factoring-lmh")
.long("p95-factoring-lmh")
.conflicts_with_all(&[
"p95-p1-factoring",
"p95-optimal-p1-factoring",
]),
)
.arg(
Arg::with_name("p95-factoring-trial-sieve")
.long("p95-factoring-trial-sieve")
.conflicts_with_all(&[
"p95-p1-factoring",
"p95-optimal-p1-factoring",
]),
)
.arg(
Arg::with_name("p95-factoring-p1-small")
.visible_alias("p95-fp1s")
.long("p95-factoring-p1-small")
.conflicts_with_all(&[
"p95-trial-factoring",
"p95-optimal-p1-factoring",
]),
)
.group(
ArgGroup::with_name("p95-workopts")
.args(&[
"p95-what-makes-most-sense",
"p95-factoring-lmh",
"p95-factoring-trial-sieve",
"p95-factoring-p1-small",
])
.multiple(false)
.required(true),
)
).get_matches_safe().map(|_| ()).map_err(|e| format!("{}", e))
} Log file: groups-3t-4o.log I accidentally found out that removing an option may change the outcomes, so I went and removed each one in turn to see what effect that had. Here's a list of what happened for each one. |
Beta Was this translation helpful? Give feedback.
-
Huh, looks like it should work. Can you try removing the groups and try to write down all conditions individually? |
Beta Was this translation helpful? Give feedback.
-
Okay, rewrote using use clap::{App, Arg, ArgGroup, SubCommand};
fn main() {
match request_from_args() {
Ok(()) => println!("Success!"),
Err(e) => println!("{}", e),
}
}
const P95_TF_REQ_CONF: [&str; 2] = ["p95-p1-factoring", "p95-optimal-p1-factoring"];
const P95_P1F_REQ_CONF: [&str; 2] = ["p95-trial-factoring", "p95-optimal-p1-factoring"];
const P95_OP1F_REQ_CONF: [&str; 2] = ["p95-trial-factoring", "p95-p1-factoring"];
const P95_WMMS_REQ_CONF: [&str; 3] = [
"p95-factoring-lmh",
"p95-factoring-trial-sieve",
"p95-factoring-p1-small",
];
const P95_FLMH_REQ_CONF: [&str; 5] = [
"p95-p1-factoring",
"p95-optimal-p1-factoring",
"p95-what-makes-most-sense",
"p95-factoring-trial-sieve",
"p95-factoring-p1-small",
];
const P95_FTS_REQ_CONF: [&str; 5] = [
"p95-p1-factoring",
"p95-optimal-p1-factoring",
"p95-what-makes-most-sense",
"p95-factoring-lmh",
"p95-factoring-p1-small",
];
const P95_FP1S_REQ_CONF: [&str; 5] = [
"p95-trial-factoring",
"p95-optimal-p1-factoring",
"p95-what-makes-most-sense",
"p95-factoring-lmh",
"p95-factoring-trial-sieve",
];
fn request_from_args() -> Result<(), String> {
App::new("primenet-rs")
.subcommand(
SubCommand::with_name("p95")
.arg(
Arg::with_name("p95-trial-factoring")
.visible_alias("p95-tf")
.long("p95-trial-factoring")
.required_unless_one(&P95_TF_REQ_CONF)
.conflicts_with_all(&P95_TF_REQ_CONF)
)
.arg(
Arg::with_name("p95-p1-factoring")
.visible_alias("p95-p1")
.long("p95-p1-factoring")
.required_unless_one(&P95_P1F_REQ_CONF)
.conflicts_with_all(&P95_P1F_REQ_CONF)
)
.arg(
Arg::with_name("p95-optimal-p1-factoring")
.visible_alias("p95-op1")
.long("p95-optimal-p1-factoring")
.required_unless_one(&P95_OP1F_REQ_CONF)
.conflicts_with_all(&P95_OP1F_REQ_CONF)
)
.arg(
Arg::with_name("p95-what-makes-most-sense")
.long("p95-what-makes-most-sense")
.required_unless_one(&P95_WMMS_REQ_CONF)
.conflicts_with_all(&P95_WMMS_REQ_CONF)
)
.arg(
Arg::with_name("p95-factoring-lmh")
.long("p95-factoring-lmh")
.required_unless_one(&P95_FLMH_REQ_CONF)
.conflicts_with_all(&P95_FLMH_REQ_CONF),
)
.arg(
Arg::with_name("p95-factoring-trial-sieve")
.long("p95-factoring-trial-sieve")
.required_unless_one(&P95_FTS_REQ_CONF)
.conflicts_with_all(&P95_FTS_REQ_CONF),
)
.arg(
Arg::with_name("p95-factoring-p1-small")
.visible_alias("p95-fp1s")
.long("p95-factoring-p1-small")
.required_unless_one(&P95_FP1S_REQ_CONF)
.conflicts_with_all(&P95_FP1S_REQ_CONF),
)
).get_matches_safe().map(|_| ()).map_err(|e| format!("{}", e))
} |
Beta Was this translation helpful? Give feedback.
-
Looks like there is an issue with arg groups. Were you trying with v2 or git master? |
Beta Was this translation helpful? Give feedback.
-
With v2. But the other thing to note is that if I scale that array method up to the full set of types and options, I still end up with no valid type+opt pairs. So it might not just be an issue with groups. |
Beta Was this translation helpful? Give feedback.
-
I'd also like to note that when I switch to the git master version, it seems to work just fine. So it appears to be specific to v2. |
Beta Was this translation helpful? Give feedback.
I'd also like to note that when I switch to the git master version, it seems to work just fine. So it appears to be specific to v2.