Stream: wg-cli

Topic: Inconsistency in usage parser


CreepySkeleton (Jul 09 2020 at 15:30, on Zulip):

While working on empty values, I have found pretty weird behavior of usage parser.

This is how I perceive usage strings:

// This clearly reads to me as "optional option that optionally takes value"
Arg::from("-o, --option [opt]")
// This reads to me as "optional option with a required value"
Arg::from("-o, --option <opt>")

But here's how clap understands it:

// "optional option with a required value"
Arg::from("-o, --option [opt]")
// "required option with a required value"
Arg::from("-o, --option <opt>")

Is it just me or which do you think should be correct?

pksunkara (Jul 12 2020 at 09:27, on Zulip):

Huh, this seems very subjective

pksunkara (Jul 12 2020 at 09:28, on Zulip):

I want to tend towards the first snippet according to my understanding of usage string conventions

pksunkara (Jul 12 2020 at 09:28, on Zulip):

But I don't know how the user would specify the required option case

CreepySkeleton (Jul 13 2020 at 19:07, on Zulip):

I presume required options are much less common than optional ones. I think it makes sense to require more verbose syntax for this case:

// "required option with an optional value"
Arg::from("-o, --option [opt]").required(true)
// "required option with a required value"
Arg::from("-o, --option <opt>").required(true)
Last update: Apr 15 2021 at 02:00UTC