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

Optional arguments are always displayed at the end in usage/help #144

Open
d4rky-pl opened this issue Dec 18, 2024 · 0 comments · May be fixed by #145
Open

Optional arguments are always displayed at the end in usage/help #144

d4rky-pl opened this issue Dec 18, 2024 · 0 comments · May be fixed by #145

Comments

@d4rky-pl
Copy link
Contributor

d4rky-pl commented Dec 18, 2024

Describe the bug

When you have a scenario where you have both optional arguments and a type: :array argument, the help incorrectly displays the optional arguments at the end of the usage, even though the catch-all array argument will get the value.

To Reproduce

require 'bundler/inline'

gemfile do
  source 'https://rubygems.org'
  gem 'dry-cli'
end

require 'dry/cli'

module MyCLI
  extend Dry::CLI::Registry

  class Test < Dry::CLI::Command
    argument :first, required: true
    argument :second, required: false # important: this one is optional
    argument :catch_all, type: :array, required: true

    def call(**kwargs)
      p kwargs
    end
  end

  register "test", Test
end

Dry::CLI.new(MyCLI).call

Actual behavior

➜  playground ruby repro.rb test --help
Command:
  repro.rb test

Usage:
  repro.rb test FIRST CATCH_ALL [SECOND]

Arguments:
  FIRST               	# REQUIRED
  SECOND              	#
  CATCH_ALL           	# REQUIRED

Options:
  --help, -h                      	# Print this help
➜  playground ruby repro.rb test first second third
{:first=>"first", :second=>"second", :catch_all=>["third"], :args=>["third"]}

Expected behavior

Usage:
  repro.rb test FIRST [SECOND] CATCH_ALL

My environment

  • Affects my production application: YES
  • Ruby version: 3.3
  • OS: Mac, Linux
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant