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

Question: how the fields are required by subcommand #515

Closed
JayiceZ opened this issue Dec 6, 2021 · 2 comments
Closed

Question: how the fields are required by subcommand #515

JayiceZ opened this issue Dec 6, 2021 · 2 comments
Labels
enhancement We would love to have this feature! Feel free to supply a PR

Comments

@JayiceZ
Copy link

JayiceZ commented Dec 6, 2021

Hi, I am new to structopt. And I am not sure is it a structopt issue or a clap issue? Here is the situation I met:

I defined it, like:

struct Opt {
    #[structopt(long)]
    cat: Option<String>,

    #[structopt(long)]
    dog: Option<String>,

    #[structopt(long)]
    host: Option<String>,

    #[structopt(subcommand)]
    cmd: Option<Cmd>,
}

enum Cmd {
    Test {
        #[structopt(long)]
        dir: Option<String>,
    },
    Debug{
        #[structopt(long)]
        remote: Option<String>,
    },
}

And what I want is: When Test SubCommand is set, one of cat and dog should be set(or it means that they are in a Group, and the group is required when Test is set); And when Debug is set, host should be set.

I have read the doc and examples, but I am not sure how to implement this function? 😭

@epage
Copy link
Contributor

epage commented Dec 6, 2021

From what I've seen so far, clap allows validation of relationship of args and groups but subcommands are effectively in another namespace, preventing them from interacting with that system.

In clap3, there is App::error to create clap-like errors for custom validation. There is also interest in generalizing clap's mechanisms so people are less likely to run into hurdles like this.

@TeXitoi
Copy link
Owner

TeXitoi commented Jan 18, 2022

This is an enhancement, and structopt is now feature frozen.

@TeXitoi TeXitoi closed this as completed Jan 18, 2022
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

No branches or pull requests

3 participants