Skip to content

Option<Vec<T> as argument #180

Closed

Description

@aurabindo

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

Activity

  1. TeXitoi commented on Apr 22, 2019

    @TeXitoi
    Owner

    Why not just Vec?

  2. jdm204 commented on Apr 30, 2019

    @jdm204

    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!

  3. TeXitoi commented on Apr 30, 2019

    @TeXitoi
    Owner

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

  4. added
    enhancement
    on Apr 30, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions