docopt.rb icon indicating copy to clipboard operation
docopt.rb copied to clipboard

Bad behavior when adding command with the same name as the main command

Open DannyBen opened this issue 7 years ago • 0 comments

I know this is not maintained (which is sad), but just in case someone picks up maintenance some day, here is a bug that caused me some headache.

The below docopt usage pattern does not work.

Usage:
   run run

Reproduce

Save the below as test.rb

require "docopt"

doc = <<DOCOPT
Usage:
  run ship
  run run

DOCOPT

begin
  p Docopt::docopt(doc)
rescue Docopt::Exit => e
  puts e.message
  exit
end

puts "execution continued"

Then run:

$ ruby test.rb

Expected Behavior

The usage pattern should be displayed, and execution should be halted

Actual Behavior

The execution continues as if a valid usage pattern was provided. Removing the run run usage pattern from the docopt string, restores correct behavior.

I believe the root cause is in #formal_usage

DannyBen avatar Mar 24 '17 09:03 DannyBen