Skip to content

ExpressibleByArgument, CaseIterable for array of enum not listing options during failure #401

@dduan

Description

@dduan

Similar to #344, when a ExpressibleByArgument & CaseIterable argument from user has incorrect value, the candidate values are shown in the error message except when said value is a member of an array.

ArgumentParser version: 1.0.3.
Swift version: swift-driver version: 1.26.21 Apple Swift version 5.5.2 (swiftlang-1300.0.47.5 clang-1300.0.29.30)

Checklist

  • If possible, I've reproduced the issue using the main branch of this package
  • I've searched for existing GitHub issues

Steps to Reproduce

With the following program:

import ArgumentParser

enum Noodle: String, CaseIterable, ExpressibleByArgument {
    case ramen
    case capellini
    case silkworm
}

@main
struct Dinner: ParsableCommand {
    @Argument
    var noodle: [Noodle]

    mutating func run() throws {
        print("Hmm, yummy \(noodle.first!).")
    }
}

Build and run with a wrong value for noodle. For a SwiftPM example

swift run dinner usbcable

Expected behavior

The error message should include candidate values for noodle like:

Error: The value 'hello' is invalid for '<noodle>'. Please provide one of 'ramen', 'capellini' or 'silkworm'.
Help:  <noodle>
Usage: dinner <noodle>
  See 'dinner --help' for more information.

Actual behavior

The output does not include candidate values for noodle

Error: The value 'hello' is invalid for '<noodle>'
Help:  <noodle>
Usage: dinner [<noodle> ...]
  See 'dinner --help' for more information.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions