Closed KrauseFx closed 9 years ago
I'm not sure, but both gems add a lot of methods to Object
so there's definitely potential for conflict. FWIW, you can use Commander's "modular" style to avoid this, and it seems to allow pry to operate normally.
Here's a small example:
require 'commander'
require 'pry'
class MyApplication
include Commander::Methods
def run
program :name, 'Foo Bar'
program :version, '1.0.0'
program :description, 'Stupid command that prints foo or bar.'
command :foo do |c|
c.action do |args, options|
binding.pry
say 'foo'
end
end
run!
end
end
MyApplication.new.run if $0 == __FILE__
Thanks @ggilder, I tried the modular code from the README:
class MyApplication
include Commander::Methods
def run
program :name, 'Foo Bar'
program :version, '1.0.0'
program :description, 'Stupid command that prints foo or bar.'
command :foo do |c|
c.syntax = 'foobar foo'
c.description = 'Displays foo'
c.action do |args, options|
say 'foo'
end
end
run!
end
end
MyApplication.new.run if $0 == __FILE__
and I get the same error:
[1] pry(Fastlane::LaneManager)> puts 'hi'
NoMethodError: undefined method `process_line' for #<Hash:0x007f980546da80>
from /Users/felixkrause/.rvm/gems/ruby-2.0.0-p481@global/gems/pry-0.10.1/lib/pry/pry_instance.rb:404:in `process_command'
Does it work on your computer?
The example I pasted above does work; can you try running it? I'm guessing there's something extra in what you're running since the script you mention doesn't actually require pry anywhere.
Thanks @ggilder, I found the problem. I've been using
require 'commander/import'
instead of
require 'commander'
Seems like require 'commander/import'
should only be used with the classic style.
Summary:
Use the modular style and change the require
statement to require 'commander'
I'm using commander for my open source project deliver and many other iOS developer tools, and this makes debugging so much easier! Thank you @ggilder!
Awesome, glad that worked out for you. We do have the modular example using require 'commander'
but we should probably call that out more explicitly.
Very cool to see another use of commander in the wild!
Running into this requirement with a thoroughly established gemspec -- github.com/nomad/cupertino. Unfortunately, I don't want to change to this require 'commander'
set, so it seems like I'm stuck without pry.
What do you use for writing/creating Gems and you want a simple debugger to start playing around with data structures while developing code? Since I can't use binding.pry
I need another solution :(
@toobulkeh wish I had a good answer for you; I always use pry too. Unfortunately it seems this is not uncommon; see for instance https://github.com/davetron5000/gli/issues/196
I've filed an issue for pry here: https://github.com/pry/pry/issues/1344
You could try the debugger gem: https://github.com/cldwalker/debugger — definitely less features but it might do in a pinch for light debugging needs.
Global namespaces are a pain :(
@toobulkeh I always use byebug instead: https://github.com/deivid-rodriguez/byebug. Does that help you?
Yeah, I used byebug last night to just move forward. Definitely debugger :+1: for ruby 2.x.
I'm pretty new to non-rails dev, so my workflow is lacking, so thanks for the help!
When using
commander
with pry I get the following error when usingbinding.pry
:I don't know if it's a
commander
or apry
issue.I still get to enter some code, but the results are not displayed.