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

Set required(false) by default for all arguments #4206

Closed
epage opened this issue Sep 12, 2022 Discussed in #4203 · 0 comments · Fixed by #4207
Closed

Set required(false) by default for all arguments #4206

epage opened this issue Sep 12, 2022 Discussed in #4203 · 0 comments · Fixed by #4207
Labels
A-builder Area: Builder API M-breaking-change Meta: Implementing or merging this will introduce a breaking change.
Milestone

Comments

@epage
Copy link
Member

epage commented Sep 12, 2022

Discussed in #4203

Originally posted by fritzrehde September 11, 2022
I am trying to simplify my argument parsing in clap.
I want to do something like this:

			arg!(-i --interval <SECS> "Seconds to wait between updates, 0 only executes once")
				.required(false)
				.default_value(DEFAULT_INTERVAL)
				.value_parser(value_parser!(f64)),

However, most of my arguments are not required (and have a default value), but I don't want to write required(false) every time. Is there an easy way to set required(false) as default for all arguments?

@epage epage added M-breaking-change Meta: Implementing or merging this will introduce a breaking change. A-builder Area: Builder API labels Sep 12, 2022
@epage epage added this to the 4.0 milestone Sep 12, 2022
epage added a commit to epage/clap that referenced this issue Sep 12, 2022
This was ported over from the usage parser which modeled after docopt.
We just never got around to implementing the rest of the syntax.

However, when considering this as a standalone feature, an
`arg!(--flag <value>)`, outside of other context, should be optional.
This is how the help would display it.

Fixes clap-rs#4206
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-builder Area: Builder API M-breaking-change Meta: Implementing or merging this will introduce a breaking change.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant