From 1ae359c3e6a598fc0fe637073e350045c3193713 Mon Sep 17 00:00:00 2001 From: Rob Gleeson Date: Wed, 11 May 2011 11:31:27 +0100 Subject: [PATCH] Rewrite the "gem-*" commands to use :arguments_required. --- lib/pry/default_commands/gems.rb | 38 +++++++++++++------------------- 1 file changed, 15 insertions(+), 23 deletions(-) diff --git a/lib/pry/default_commands/gems.rb b/lib/pry/default_commands/gems.rb index a2dfe53e..b658fc74 100644 --- a/lib/pry/default_commands/gems.rb +++ b/lib/pry/default_commands/gems.rb @@ -3,33 +3,25 @@ class Pry Gems = Pry::CommandSet.new do - command "gem-install", "Install a gem and refresh the gem cache." do |gem| - if gem - if File.writable? Gem.dir - installer = Gem::DependencyInstaller.new :install_dir => Gem.dir - installer.install gem - output.puts "Gem '#{text.green gem}' installed." - elsif File.writable? Gem.user_dir - installer = Gem::DependencyInstaller.new :install_dir => Gem.user_dir - installer.install gem - output.puts "Gem '#{text.green gem}' installed to your user directory" - else - output.puts "Insufficient permissions to install `#{text.green gem}`" - end - - Gem.refresh + command "gem-install", "Install a gem and refresh the gem cache.", :arguments_required => 1 do |gem| + if File.writable? Gem.dir + installer = Gem::DependencyInstaller.new :install_dir => Gem.dir + installer.install gem + output.puts "Gem '#{text.green gem}' installed." + elsif File.writable? Gem.user_dir + installer = Gem::DependencyInstaller.new :install_dir => Gem.user_dir + installer.install gem + output.puts "Gem '#{text.green gem}' installed to your user directory" else - output.puts "gem-install requires the name of a gem as an argument." + output.puts "Insufficient permissions to install `#{text.green gem}`" end + + Gem.refresh end - 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 + command "gem-cd", "Change working directory to specified gem's directory.", :arguments_required => 1 do |gem| + spec = Gem.source_index.find_name(gem).first + spec ? Dir.chdir(spec.full_gem_path) : output.puts("Gem `#{gem}` not found.") end