Skip to content

enum should be enforced for all values of type: array #783

@movermeyer

Description

@movermeyer

🌈

enum was added in #237, but it originally only validated type: string values.

Validation of type: numeric values was added in #386

I expected all values of my type: array option to also be validated.

Example

cli.rb:

require "thor"

class MyCLI < Thor
  desc "array_with_enum [--fruits=apple banana]", "Demo of using an enum with an array"
  option :fruits, type: :array, enum: ["apple", "banana", "clementine"]
  def array_with_enum
    puts "fruits: #{options[:fruits]}"
  end
end

MyCLI.start(ARGV)

This works:

ruby ./cli.rb array_with_enum --fruits=banana apple
fruits: ["banana", "apple"]

This also works:

ruby ./cli.rb array_with_enum --fruits=kiwi
fruits: ["kiwi"]

but shouldn't since "kiwi" is not a fruit in the enum.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions