From 1750fe4d7895b4f9a822cb9d8cdd7b9386bc8886 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mon=20ou=C3=AFe?= Date: Sat, 7 May 2011 07:32:05 +0200 Subject: [PATCH] Got rid of CommandSet#name --- lib/pry/command_set.rb | 9 +++---- lib/pry/commands.rb | 2 +- lib/pry/default_commands/context.rb | 2 +- lib/pry/default_commands/documentation.rb | 2 +- lib/pry/default_commands/easter_eggs.rb | 2 +- lib/pry/default_commands/gems.rb | 2 +- lib/pry/default_commands/input.rb | 2 +- lib/pry/default_commands/introspection.rb | 2 +- lib/pry/default_commands/ls.rb | 2 +- lib/pry/default_commands/shell.rb | 2 +- test/helper.rb | 2 +- test/test_command_set.rb | 16 +++++------- test/test_pry.rb | 30 +++++++++++------------ 13 files changed, 34 insertions(+), 41 deletions(-) diff --git a/lib/pry/command_set.rb b/lib/pry/command_set.rb index 4b022205..71bcde83 100644 --- a/lib/pry/command_set.rb +++ b/lib/pry/command_set.rb @@ -34,15 +34,12 @@ class Pry include Pry::Helpers::BaseHelpers attr_reader :commands - attr_reader :name attr_reader :helper_module - # @param [Symbol] name Name of the command set # @param [Array] imported_sets Sets which will be imported # automatically # @yield Optional block run to define commands - def initialize(name, *imported_sets, &block) - @name = name + def initialize(*imported_sets, &block) @commands = {} @helper_module = Module.new @@ -65,7 +62,7 @@ class Pry # parameters passed into the block will be strings. Successive # command parameters are separated by whitespace at the Pry prompt. # @example - # MyCommands = Pry::CommandSet.new :mine do + # MyCommands = Pry::CommandSet.new do # command "greet", "Greet somebody" do |name| # puts "Good afternoon #{name.capitalize}!" # end @@ -153,7 +150,7 @@ class Pry # @param [String] name The command name. # @param [String] description The command description. # @example - # MyCommands = Pry::CommandSet.new :test do + # MyCommands = Pry::CommandSet.new do # desc "help", "help description" # end def desc(name, description) diff --git a/lib/pry/commands.rb b/lib/pry/commands.rb index 2eb448bd..9dfb8783 100644 --- a/lib/pry/commands.rb +++ b/lib/pry/commands.rb @@ -9,7 +9,7 @@ require "pry/default_commands/easter_eggs" class Pry # Default commands used by Pry. - Commands = Pry::CommandSet.new :default do + Commands = Pry::CommandSet.new do import DefaultCommands::Documentation import DefaultCommands::Gems import DefaultCommands::Context diff --git a/lib/pry/default_commands/context.rb b/lib/pry/default_commands/context.rb index ab35df67..fc76cd56 100644 --- a/lib/pry/default_commands/context.rb +++ b/lib/pry/default_commands/context.rb @@ -3,7 +3,7 @@ require "pry/default_commands/ls" class Pry module DefaultCommands - Context = Pry::CommandSet.new :context do + Context = Pry::CommandSet.new do import Ls command "cd", "Start a Pry session on VAR (use `cd ..` to go back and `cd /` to return to Pry top-level)", :keep_retval => true do |obj| diff --git a/lib/pry/default_commands/documentation.rb b/lib/pry/default_commands/documentation.rb index 95c677fd..6c209063 100644 --- a/lib/pry/default_commands/documentation.rb +++ b/lib/pry/default_commands/documentation.rb @@ -1,7 +1,7 @@ class Pry module DefaultCommands - Documentation = Pry::CommandSet.new :gems do + Documentation = Pry::CommandSet.new do command "ri", "View ri documentation. e.g `ri Array#each`" do |*args| run ".ri", *args diff --git a/lib/pry/default_commands/easter_eggs.rb b/lib/pry/default_commands/easter_eggs.rb index 435abb4f..50c32eff 100644 --- a/lib/pry/default_commands/easter_eggs.rb +++ b/lib/pry/default_commands/easter_eggs.rb @@ -1,7 +1,7 @@ class Pry module DefaultCommands - EasterEggs = Pry::CommandSet.new :easter_eggs do + EasterEggs = Pry::CommandSet.new do command "game", "" do |highest| highest = highest ? highest.to_i : 100 diff --git a/lib/pry/default_commands/gems.rb b/lib/pry/default_commands/gems.rb index 1e3ffb34..030ece10 100644 --- a/lib/pry/default_commands/gems.rb +++ b/lib/pry/default_commands/gems.rb @@ -1,7 +1,7 @@ class Pry module DefaultCommands - Gems = Pry::CommandSet.new :gems do + Gems = Pry::CommandSet.new do command "gem-install", "Install a gem and refresh the gem cache." do |gem_name| gem_home = Gem.instance_variable_get(:@gem_home) diff --git a/lib/pry/default_commands/input.rb b/lib/pry/default_commands/input.rb index 793afe4d..6c2c5ed4 100644 --- a/lib/pry/default_commands/input.rb +++ b/lib/pry/default_commands/input.rb @@ -1,7 +1,7 @@ class Pry module DefaultCommands - Input = Pry::CommandSet.new :input do + Input = Pry::CommandSet.new do command "!", "Clear the input buffer. Useful if the parsing process goes wrong and you get stuck in the read loop." do output.puts "Input buffer cleared!" diff --git a/lib/pry/default_commands/introspection.rb b/lib/pry/default_commands/introspection.rb index b2a945d1..c9e7225e 100644 --- a/lib/pry/default_commands/introspection.rb +++ b/lib/pry/default_commands/introspection.rb @@ -1,7 +1,7 @@ class Pry module DefaultCommands - Introspection = Pry::CommandSet.new :introspection do + Introspection = Pry::CommandSet.new do command "show-method", "Show the source for METH. Type `show-method --help` for more info. Aliases: $, show-source" do |*args| target = target() diff --git a/lib/pry/default_commands/ls.rb b/lib/pry/default_commands/ls.rb index fb631dd1..e4da6628 100644 --- a/lib/pry/default_commands/ls.rb +++ b/lib/pry/default_commands/ls.rb @@ -1,7 +1,7 @@ class Pry module DefaultCommands - Ls = Pry::CommandSet.new :ls do + Ls = Pry::CommandSet.new do command "ls", "Show the list of vars and methods in the current scope. Type `ls --help` for more info." do |*args| options = {} diff --git a/lib/pry/default_commands/shell.rb b/lib/pry/default_commands/shell.rb index 2b81351a..06478a9c 100644 --- a/lib/pry/default_commands/shell.rb +++ b/lib/pry/default_commands/shell.rb @@ -1,7 +1,7 @@ class Pry module DefaultCommands - Shell = Pry::CommandSet.new :shell do + Shell = Pry::CommandSet.new do # this cannot be accessed, it's just for help purposes. command ".", "All text following a '.' is forwarded to the shell." do diff --git a/test/helper.rb b/test/helper.rb index 09ef5edc..31f9d708 100644 --- a/test/helper.rb +++ b/test/helper.rb @@ -67,7 +67,7 @@ class Pry end -CommandTester = Pry::CommandSet.new :test do +CommandTester = Pry::CommandSet.new do command "command1", "command 1 test" do output.puts "command1" end diff --git a/test/test_command_set.rb b/test/test_command_set.rb index e2edea70..d8244a53 100644 --- a/test/test_command_set.rb +++ b/test/test_command_set.rb @@ -2,11 +2,7 @@ require 'helper' describe Pry::CommandSet do before do - @set = Pry::CommandSet.new(:some_name) - end - - it 'should use the name specified at creation' do - @set.name.should == :some_name + @set = Pry::CommandSet.new end it 'should call the block used for the command when it is called' do @@ -54,7 +50,7 @@ describe Pry::CommandSet do it 'should be able to import some commands from other sets' do run = false - other_set = Pry::CommandSet.new :foo do + other_set = Pry::CommandSet.new do command('foo') { run = true } command('bar') {} end @@ -72,7 +68,7 @@ describe Pry::CommandSet do it 'should be able to import a whole set' do run = [] - other_set = Pry::CommandSet.new :foo do + other_set = Pry::CommandSet.new do command('foo') { run << true } command('bar') { run << true } end @@ -88,7 +84,7 @@ describe Pry::CommandSet do run = false @set.command('foo') { run = true } - Pry::CommandSet.new(:other, @set).run_command nil, 'foo' + Pry::CommandSet.new(@set).run_command nil, 'foo' run.should == true end @@ -157,7 +153,7 @@ describe Pry::CommandSet do end it 'should import helpers from imported sets' do - imported_set = Pry::CommandSet.new :test do + imported_set = Pry::CommandSet.new do helpers do def imported_helper_method; end end @@ -169,7 +165,7 @@ describe Pry::CommandSet do end it 'should import helpers even if only some commands are imported' do - imported_set = Pry::CommandSet.new :test do + imported_set = Pry::CommandSet.new do helpers do def imported_helper_method; end end diff --git a/test/test_pry.rb b/test/test_pry.rb index 95c33449..2199f16f 100644 --- a/test/test_pry.rb +++ b/test/test_pry.rb @@ -425,7 +425,7 @@ describe Pry do describe "commands" do it 'should interpolate ruby code into commands' do - klass = Pry::CommandSet.new :test do + klass = Pry::CommandSet.new do command "hello", "", :keep_retval => true do |arg| arg end @@ -449,7 +449,7 @@ describe Pry do end it 'should define a command that keeps its return value' do - klass = Pry::CommandSet.new :test do + klass = Pry::CommandSet.new do command "hello", "", :keep_retval => true do :kept_hello end @@ -461,7 +461,7 @@ describe Pry do end it 'should define a command that does NOT keep its return value' do - klass = Pry::CommandSet.new :test do + klass = Pry::CommandSet.new do command "hello", "", :keep_retval => false do :kept_hello end @@ -473,7 +473,7 @@ describe Pry do end it 'should set the commands default, and the default should be overridable' do - klass = Pry::CommandSet.new :test do + klass = Pry::CommandSet.new do command "hello" do output.puts "hello world" end @@ -485,7 +485,7 @@ describe Pry do Pry.new(:input => InputTester.new("hello"), :output => str_output).rep str_output.string.should =~ /hello world/ - other_klass = Pry::CommandSet.new :test2 do + other_klass = Pry::CommandSet.new do command "goodbye", "" do output.puts "goodbye world" end @@ -498,7 +498,7 @@ describe Pry do end it 'should inherit "help" command from Pry::CommandBase' do - klass = Pry::CommandSet.new :test do + klass = Pry::CommandSet.new do command "h", "h command" do end end @@ -510,7 +510,7 @@ describe Pry do end it 'should inherit commands from Pry::Commands' do - klass = Pry::CommandSet.new :test, Pry::Commands do + klass = Pry::CommandSet.new Pry::Commands do command "v" do end end @@ -522,7 +522,7 @@ describe Pry do end it 'should alias a command with another command' do - klass = Pry::CommandSet.new :test do + klass = Pry::CommandSet.new do alias_command "help2", "help" end @@ -531,7 +531,7 @@ describe Pry do end it 'should change description of a command using desc' do - klass = Pry::CommandSet.new :test do; end + klass = Pry::CommandSet.new do; end orig = klass.commands["help"].description klass.instance_eval do desc "help", "blah" @@ -541,7 +541,7 @@ describe Pry do end it 'should run a command from within a command' do - klass = Pry::CommandSet.new :test do + klass = Pry::CommandSet.new do command "v" do output.puts "v command" end @@ -557,13 +557,13 @@ describe Pry do end it 'should enable an inherited method to access opts and output and target, due to instance_exec' do - klass = Pry::CommandSet.new :test do + klass = Pry::CommandSet.new do command "v" do output.puts "#{target.eval('self')}" end end - child_klass = Pry::CommandSet.new :test2, klass do + child_klass = Pry::CommandSet.new klass do end str_output = StringIO.new @@ -574,7 +574,7 @@ describe Pry do end it 'should import commands from another command object' do - klass = Pry::CommandSet.new :test do + klass = Pry::CommandSet.new do import_from Pry::Commands, "ls", "jump-to" end @@ -583,7 +583,7 @@ describe Pry do end it 'should delete some inherited commands when using delete method' do - klass = Pry::CommandSet.new :test, Pry::Commands do + klass = Pry::CommandSet.new Pry::Commands do command "v" do end @@ -601,7 +601,7 @@ describe Pry do end it 'should override some inherited commands' do - klass = Pry::CommandSet.new :test, Pry::Commands do + klass = Pry::CommandSet.new Pry::Commands do command "jump-to" do output.puts "jump-to the music" end