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

Parsing complex data into list #457

Closed
elkowar opened this issue Dec 28, 2020 · 3 comments
Closed

Parsing complex data into list #457

elkowar opened this issue Dec 28, 2020 · 3 comments

Comments

@elkowar
Copy link

elkowar commented Dec 28, 2020

One thing that, as far as i can tell, is not yet really possible with structopt is parsing more complicated invocations as lists.
What i mean by this is that it could be possible to allow for something like

#[derive(StructOpt)]
pub enum SomeSubCommand {
  #[structopt(name = "open")]
  OpenWindow(Vec<OpenWindow>)
  // and others, if desired, of course
}

#[derive(StructOpt)]
pub struct OpenWindow {
  name: String,
  #[structopt(short)]
  x: i32,
  #[structopt(short)]
  y: i32,
}

Which would then result in the command line API

myapp open \
  foo -x 12 -y 12 \
  bar -x 100 -y 200 \
  baz -x 200 -y 250

Resulting in a data-structure of

SomeSubCommand::OpenWindow(vec![
    OpenWindow { name: "foo", x: 12, y: 12 },
    OpenWindow { name: "bar", x: 100, y: 200 },
    OpenWindow { name: "baz", x: 200, y: 250 }
])

With the current structopt featureset, the only way i could see how i could implement this API would be to use an external subcommand, with which I'd loose most of the niceties offered by structuopt.

@TeXitoi
Copy link
Owner

TeXitoi commented Dec 28, 2020

AFAIK, clap can't parse this, and structopt rely on clap for parsing (structopt is "just" an interface to clap).

@elkowar
Copy link
Author

elkowar commented Dec 28, 2020

Right, makes sense! I'll close this and file an issue with clap instead 👍

@elkowar elkowar closed this as completed Dec 28, 2020
@elkowar
Copy link
Author

elkowar commented Dec 28, 2020

Note: after a quick look, it seems that an issue for this already exists in clap: clap-rs/clap#1704
Progress seems to be going rather slowly though :/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants