You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
First thank you for structopt, it's such a great piece of software. :)
I'm not sure if what I've encountered is a bug or expected behaviour, but I would love to hear if there are alternatives where I can accept a single value regardless of order for my argument. This situation can be best explained with the following examples:
Problematic input order
$ cargo run -- -b 1 --p 80127.0.0.1
error:Invalid value for'--ports<ports>...': invalid digit found in string
Working alternatives
$ cargo run -- -b 1 -p 80,127.0.0.1// OR
$ cargo run -- -p 80 -b 1127.0.0.1
I'm not sure if I have the wrong mental model and it's expected that this wouldn't work with FromStr.
Nit: I think you're confusing --p with -p in the first example.
Anyway, the problem here is that clapfirst parses the args according to the spec, and only then tries to validate them. You're expecting that -p 80 127.0.0.1 is parsed as <option> <value> <FromStr failed, stop here>, but it's parsed as <option> <value1> <value2, validation will fail>. Basically, there's no way to say "this option takes multiple values, but only as long as the validator passes". See clap-rs/clap#2122
We can't do anything about it in structopt. As a workaround, I suggest you to redesign your CLI:
Make -p take only one value, but allow it to occur more than once:
I see, thank you for the insight @CreepySkeleton! Thinking in retrospect it makes a lot of sense.
Multiple -p are not an option due to the sheer amount of ports, but making address an option might be possible. Worst case scenario I might take the custom parser route and do the validation myself for this argument. Thank you so much for the help!
First thank you for structopt, it's such a great piece of software. :)
I'm not sure if what I've encountered is a bug or expected behaviour, but I would love to hear if there are alternatives where I can accept a single value regardless of order for my argument. This situation can be best explained with the following examples:
Problematic input order
Working alternatives
I'm not sure if I have the wrong mental model and it's expected that this wouldn't work with
FromStr
.Minimum setup in order to replicate:
The text was updated successfully, but these errors were encountered: