Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Option<Vec<T> as argument #180

Closed
aurabindo opened this issue Apr 22, 2019 · 3 comments · Fixed by #191
Closed

Option<Vec<T> as argument #180

aurabindo opened this issue Apr 22, 2019 · 3 comments · Fixed by #191
Labels
enhancement We would love to have this feature! Feel free to supply a PR

Comments

@aurabindo
Copy link

Hi,

An argument with Option<Vec> does not seem to work. Are there any workarounds ?

#[derive(StructOpt, Debug)]
pub enum DevCmds {
    #[structopt(name = "list", alias = "show")]
    Cmd1 {
        optional_args: Option<Vec<String>>,
    },

This produces errors like:

error[E0277]: the trait bound `std::vec::Vec<T>: std::str::FromStr` is not satisfied
@TeXitoi
Copy link
Owner

TeXitoi commented Apr 22, 2019

Why not just Vec?

@jdm204
Copy link

jdm204 commented Apr 30, 2019

Hi, I can't speak for @aurabindo, but for my use case I'd like to differentiate between

./my-app                                                     // None
./my-app --optional-multiple                       // Some(vec![])
./my-app --optional-multiple ARG1 ARG2  // Some(vec![ARG1, ARG2])

is this currently possible without Option<Vec<T>>? Thanks for your work on structopt!

@TeXitoi
Copy link
Owner

TeXitoi commented Apr 30, 2019

That's not possible with structopt today. That's a structopt limitation, clap allows to do that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement We would love to have this feature! Feel free to supply a PR
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants