apple / swift-argument-parser

Straightforward, type-safe argument parsing for Swift
Apache License 2.0
3.34k stars 322 forks source link

Use compact valueName by default #37

Open ddunbar opened 4 years ago

ddunbar commented 4 years ago

By default, ArgumentParser currently uses a ArgumentHelp.valueName derived from the option name. While this is a nice standard default, I think it often leads to overly verbose --help text, and customizing with ArgumentHelp makes declaration a little verbose (super kudos for having it possible in v0.0.1 though!).

I think there is an argument to be made for having ArgumentParser use a default value name for well-known and common types, for example, using N for integral types.

One upside of this is that it helps communicate the expected type.

I can understand if this is perceived to be too much magic, though...

natecook1000 commented 4 years ago

Something shorter would make for better defaults, especially with how long some property names can get. I like the idea of trying to select a value name that's appropriate for the type — we may even be able to hook into more information, like if you've indicated that the property is a file for autocomplete purposes (a la #1). What other default names would you expect beyond N for integers and something like value in the default case?

ddunbar commented 4 years ago

I'm not sure, very obvious ones to me are:

One thing I wondered was if it would make sense to actually make the ExpressibleByArgument be able to optionally provide this. So URL adopting could be <url>, for example.

@vlm any thoughts on this?

vlm commented 4 years ago

Yes, I'd love it to be something that can be set in the ExpressibleByArgument.

rauhul commented 1 year ago

Suppose we had a ExpressibleByArgument.defaultValueName to mirror ArgumentHelp.valueName... how would we know whether to the defaultValueName, valueName, or the argument's property name as the valueName?

natecook1000 commented 1 year ago

ArgumentHelp.valueName is more local, so it would override anything from the protocol.

rauhul commented 1 year ago

So ArgumentHelp.valueName > ExpressibleByArgument.defaultValueName > @Arg/Opt/Flag name?