Skip to content

Inconsistent error reporting involving flags of Optional enums #61

@glessard

Description

@glessard

Here is a command with two flags whose type differs only by optionality (and spelling)

enum Enum: String, CaseIterable { case s, t, u }

struct Options: ParsableCommand {
  @Flag(name: .short, exclusivity: .exclusive) var flag1: Enum
  @Flag(name: .long,  exclusivity: .exclusive) var flag2: Enum?
}
let options = Options.parseOrExit()

The two flags will report errors rather differently:

$ options -s -t
Error: Value to be set with flag '-t' had already been set with flag '-s'
Usage: options -s -t -u [--s] [--t] [--u]
$ options --s --t
Error: Unexpected argument 't'
Usage: options -s -t -u [--s] [--t] [--u]

Cause: the two Flag instances use two very different constructors. Presumably they diverged during development.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions