apple / swift-argument-parser

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

Add ability to retrieve list of possible options for Option property #647

Open bripeticca opened 2 months ago

bripeticca commented 2 months ago

Previously, information regarding a custom Option type's possible values was lost when generating subsequent structures in the pipeline to describe the argument. This would largely have to be defined by the user in the discussion string property in ArgumentHelp and would provide no mechanism to directly access the allowable values for a custom Option.

This adds an extra static property on ExpressibleByArgument labelled defaultValueDescriptions, which maps the value name to its description. It is up to the user to implement the defaultValueDescription for their custom CaseIterable type to fully support this behaviour. Further refactoring has been made downstream to the ArgumentDefinition and subsequent structures describing the argument to allow the ability to retrieve the value descriptions from the ExpressibleByArgument type, making information about the property more visible and accessible.

A new enumeration ArgumentDiscussion has been introduced to better encapsulate the discussion information for an argument, and includes cases for discussion sections that contain only static text, as well as cases that include a list of argument values that derive from a type that implements ExpressibleByArgument, CaseIterable and RawRepresentable.

Addresses #637

Checklist

bripeticca commented 3 weeks ago

@swift-ci please test

bripeticca commented 3 weeks ago

@swift-ci please test

bripeticca commented 2 weeks ago

@swift-ci please test