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

SubcommandsNegateReqs completely disables Arg.required #188

Closed
wenLiangcan opened this issue Aug 24, 2015 · 10 comments · Fixed by #189
Closed

SubcommandsNegateReqs completely disables Arg.required #188

wenLiangcan opened this issue Aug 24, 2015 · 10 comments · Fixed by #189
Assignees
Labels
A-builder Area: Builder API C-bug Category: Updating dependencies

Comments

@wenLiangcan
Copy link

App::new("my_app")
                .setting(AppSettings::SubcommandsNegateReqs)
                .arg(Arg::with_name("test")
                       .required(true)
                       .index(1))
                .subcommand(SubCommand::with_name("sub1"))
                .subcommand(SubCommand::with_name("sub1"))

While running:

$ my_app

.required(true) has no effect.

@Vinatorul
Copy link
Contributor

Hello, as you can read in documentation about AppSettings::SubcommandsNegateReqs.

Allows subcommands to override all requirements of the parent (this command). For example if you had a subcommand or even top level application which had a required arguments that are only required as long as there is no subcommand present.

NOTE: This defaults to false (using subcommand does not negate requirements)

So it is expected behavior.
If you don't want for subcommands to override requires - just delete .setting(AppSettings::SubcommandsNegateReqs) call.

Please let me know if you still have problems or not.

@wenLiangcan
Copy link
Author

But in my opinion, I think <test> should be required when running my_app without sub1 and sub2.

I have no idea why we need SubcommandsNegateReqs if it should behave as you described, because we can simply omit the declaration of the parent's requirements or declare the parent without the subcommands.

@Vinatorul
Copy link
Contributor

Oh, I'm sorry, you are right, it's a bug.

@Vinatorul Vinatorul added C-bug Category: Updating dependencies P1: urgent and removed T: RFC / question labels Aug 24, 2015
@kbknapp
Copy link
Member

kbknapp commented Aug 24, 2015

@wenLiangcan Thanks for finding and taking the time to file this issue! As @Vinatorul said, it's in fact a bug. We'll get this patched and put out v1.2.3 shortly 👍

@Vinatorul
Copy link
Contributor

@kbknapp I can do it, when come home in about one hour.

@kbknapp
Copy link
Member

kbknapp commented Aug 24, 2015

Sounds good thanks!

@wenLiangcan
Copy link
Author

Thanks for the quick responses, @Vinatorul , @kbknapp 😄

@kbknapp
Copy link
Member

kbknapp commented Aug 24, 2015

@wenLiangcan the new version (v1.2.3) has been published to crates.io thanks to @Vinatorul

Let us know if you have any other questions or issues! 😄

@wenLiangcan
Copy link
Author

@kbknapp Thank you, I tried the new version and it works well now!

Thanks for your great job, @Vinatorul 👏

@Vinatorul
Copy link
Contributor

At your service ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-builder Area: Builder API C-bug Category: Updating dependencies
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants