1
0
Fork 0
mirror of https://github.com/pry/pry.git synced 2022-11-09 12:35:05 -05:00

Got rid of CommandSet#name

This commit is contained in:
Mon ouïe 2011-05-07 07:32:05 +02:00
parent 495e00caa7
commit 1750fe4d78
13 changed files with 34 additions and 41 deletions

View file

@ -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<CommandSet>] 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)

View file

@ -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

View file

@ -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|

View file

@ -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

View file

@ -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

View file

@ -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)

View file

@ -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!"

View file

@ -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()

View file

@ -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 = {}

View file

@ -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 ".<shell command>", "All text following a '.' is forwarded to the shell." do

View file

@ -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

View file

@ -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

View file

@ -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