Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
2 tasks done
dduan opened this issue Feb 3, 2022 · 1 comment
Closed
2 tasks done
Labels
enhancement New feature or request

Comments

@dduan
Copy link
Contributor

dduan commented Feb 3, 2022

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.
@natecook1000 natecook1000 added the enhancement New feature or request label Feb 14, 2022
konomae added a commit to konomae/swift-argument-parser that referenced this issue May 13, 2022
When an array of argument values fails to parse, no custom error message is
provided, and a list of valid candidate values is available, include the
list as part of the error message.

Addresses apple#401.
konomae added a commit to konomae/swift-argument-parser that referenced this issue May 13, 2022
When an array of argument values fails to parse, no custom error message is
provided, and a list of valid candidate values is available, include the
list as part of the error message.

Addresses apple#401.
natecook1000 pushed a commit that referenced this issue May 17, 2022
When an array of argument values fails to parse, no custom error message is
provided, and a list of valid candidate values is available, include the
list as part of the error message.

Addresses #401.
@natecook1000
Copy link
Member

Fixed by #445 - thanks @konomae!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants