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

Cannot print dictionary items? #34

Open
Behinder opened this issue May 18, 2018 · 2 comments
Open

Cannot print dictionary items? #34

Behinder opened this issue May 18, 2018 · 2 comments

Comments

@Behinder
Copy link

This is my simple code:
#encoding: UTF-8
#!/usr/bin/env ruby
require "net/http"
require "docopt"
require "uri"

doc=<<DOCOPT

Usage:
screengrab (application_id) [-c=(us|pl|de|gb|au)]
screengrab -h|--help
screengrab --version

Options:
-h|--help Show this help
--version Show version
-c=(us|pl|de|gb|au) Lookup in specific Store.

DOCOPT

begin
require "pp"
options = Docopt::docopt(doc,version:"1.0")
pp options
rescue Docopt::Exit => e
puts e.message
exit 1
end

no matter what I do, command pp options do not produce any dictionary on screen

@Behinder
Copy link
Author

I tried to run test example by ruby -d and got weird results:

Exception LoadError' at /Users/sebastian/.rvm/rubies/ruby-2.5.1/lib/ruby/2.5.0/rubygems.rb:1388 - cannot load such file -- rubygems/defaults/operating_system Exception LoadError' at /Users/sebastian/.rvm/rubies/ruby-2.5.1/lib/ruby/2.5.0/rubygems.rb:1397 - cannot load such file -- rubygems/defaults/ruby
Exception LoadError' at /Users/sebastian/.rvm/rubies/ruby-2.5.1/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59 - cannot load such file -- docopt Exception Docopt::Exit' at /Users/sebastian/.rvm/gems/ruby-2.5.1/gems/docopt-0.6.1/lib/docopt.rb:667 - Docopt::Exit

WTF?

@Ignateus
Copy link

Ignateus commented Nov 5, 2021

This is something I struggled with but I was able to get around it by using pry.

Sample code:
require "docopt"
require "pry"

doc = <<DOCOPT
Usage:
#{__FILE__} <country> <state> <city> <street_name>
Options:
-h --help show this help message and exit
DOCOPT

begin
require "pp"
pp = Docopt::docopt(doc)
binding.pry
rescue Docopt::Exit => e
puts e.message
end

The output will be something like this:
19: DOCOPT
20:
21: begin
22: require "pp"
23: pp = Docopt::docopt(doc)
=> 24: binding.pry
25: rescue Docopt::Exit => e
26: puts e.message
27: end
28:
29: # SETUP for calls.

[1] pry(main)> pp
=> {"<country>"=>"usa",
"<state>"=>"tx",
"<city>"=>"houston",
"<street_name>"=>"Clark county"}

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

2 participants