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

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

Closed
DannyBen opened this issue Mar 24, 2017 · 2 comments
Closed

Comments

@DannyBen
Copy link

DannyBen commented Mar 24, 2017

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
Copy link
Author

DannyBen commented Jan 29, 2023

Any slim chance that someone can help resolve this?
I am willing to try myself if PRs are accepted.

This is impacting my docopt-based Runfile gem, which has an executable named run.

I am pasting a more realistic example here:

require "docopt"
doc = <<~DOCOPT
  Usage:
    run server start
    run server stop
    run server run
DOCOPT

begin
  pp Docopt::docopt doc
rescue Docopt::Exit => e
  puts e.message
end

Output

# the `run` command is completely omitted
$ ruby test.rb
{"server"=>false, "start"=>false, "stop"=>false}

# ... and not accepted of course
$ ruby test.rb server run
Usage:
  run server start
  run server stop
  run server run

@DannyBen
Copy link
Author

DannyBen commented Feb 2, 2023

Fixed in https://github.com/DannyBen/docopt_ng

@DannyBen DannyBen closed this as completed Feb 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant