mirror of
https://github.com/pry/pry.git
synced 2022-11-09 12:35:05 -05:00
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
1 changed files with 7 additions and 5 deletions
|
@ -28,11 +28,13 @@ class Pry
|
|||
output.puts "Refreshed gem cache."
|
||||
end
|
||||
|
||||
command "gem-cd", "Change working directory to specified gem's directory." do |gem_name|
|
||||
require 'rubygems'
|
||||
gem_spec = Gem.source_index.find_name(gem_name).first
|
||||
next output.puts("Gem `#{gem_name}` not found.") if !gem_spec
|
||||
Dir.chdir(File.expand_path(gem_spec.full_gem_path))
|
||||
command "gem-cd", "Change working directory to specified gem's directory." do |gem|
|
||||
if gem
|
||||
spec = Gem.source_index.find_name(gem).first
|
||||
spec ? Dir.chdir(spec.full_gem_path) : output.puts("Gem `#{gem}` not found.")
|
||||
else
|
||||
output.puts 'gem-cd requires the name of a gem as an argument.'
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue