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

Unlisted value fails for option, but passes for argument #126

Open
svoop opened this issue May 4, 2023 · 0 comments
Open

Unlisted value fails for option, but passes for argument #126

svoop opened this issue May 4, 2023 · 0 comments

Comments

@svoop
Copy link

svoop commented May 4, 2023

Describe the bug

Given the following example:

#!/usr/bin/env ruby
require "bundler/setup"
require "dry/cli"

module Foo
  module CLI
    module Commands
      extend Dry::CLI::Registry

      class Start < Dry::CLI::Command
        argument :arg, values: %w(one two)
        option :opt, values: %w(one two)

        def call(arg: nil, opt: nil, **)
          puts "ARG: #{arg.inspect} / OPT: #{opt.inspect}"
        end
      end

      register "start", Start
    end
  end
end

Dry::CLI.new(Foo::CLI::Commands).call

The following somewhat unexpected behaviour occurs:

example start --opt=one      # ARG: nil / OPT: "one"
example start --opt=three    # ERROR: was called with arguments "--opt=three"
example start one            # ARG: "one" / OPT: nil
example start three          # ARG: "three" / OPT: nil     <-- OOPS

The last one should also result in an error IMO.

My environment

  • Affects my production application: NO (but soon :-)
  • Ruby version: 3.2
  • OS: macOS Ventura
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant