Skip to content

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

Open
@d4rky-pl

Description

@d4rky-pl

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions