Re factor the "gem-cd" command.
- Add a argument check, so the command doesn't blow up. - Simplify the code.
This commit is contained in:
parent
42eca4fbb7
commit
045f3fa8d5
|
@ -28,11 +28,13 @@ class Pry
|
||||||
output.puts "Refreshed gem cache."
|
output.puts "Refreshed gem cache."
|
||||||
end
|
end
|
||||||
|
|
||||||
command "gem-cd", "Change working directory to specified gem's directory." do |gem_name|
|
command "gem-cd", "Change working directory to specified gem's directory." do |gem|
|
||||||
require 'rubygems'
|
if gem
|
||||||
gem_spec = Gem.source_index.find_name(gem_name).first
|
spec = Gem.source_index.find_name(gem).first
|
||||||
next output.puts("Gem `#{gem_name}` not found.") if !gem_spec
|
spec ? Dir.chdir(spec.full_gem_path) : output.puts("Gem `#{gem}` not found.")
|
||||||
Dir.chdir(File.expand_path(gem_spec.full_gem_path))
|
else
|
||||||
|
output.puts 'gem-cd requires the name of a gem as an argument.'
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue