SwiftCLI icon indicating copy to clipboard operation
SwiftCLI copied to clipboard

Key and Param default value

Open yonaskolb opened this issue 5 years ago • 1 comments

It would be awesome to have an optional default value for Param and Key. This would allow:

  • setting the default value in the same place as the rest of the option configuration, instead of down in execute with option ?? defaultValue
  • allow Param and Key to have non optional types (Param already supports non optional types but currently fails if value not supplied)
  • allow an option to HelpMessageGenerator that would print the default value of options, perhaps after the description eg: " Defaults to \(defaultValue)"
@Key("--type", "-t", description: "The type of dump to output", defaultValue: .yaml)
private var dumpType: DumpType

yonaskolb avatar Jan 05 '20 01:01 yonaskolb

This was near impossible when property wrappers were new and the Swift compiler crashed while doing just about anything with property wrappers. I think it's worth attempting this feature again now in Swift 5.4 though -- will implement when I get a chance

jakeheis avatar May 26 '21 14:05 jakeheis