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

command_class no longer alias for create_command

* removed as an alias
* converted remaining commands over to create_command
* removed references in tests
This commit is contained in:
John Mair 2012-01-22 12:17:43 +13:00
parent d3e854b26e
commit 312bb7eee4
5 changed files with 25 additions and 26 deletions

View file

@ -1,7 +1,7 @@
class Pry
# The super-class of all commands, new commands should be created by calling
# {Pry::CommandSet#command} which creates a BlockCommand or {Pry::CommandSet#command_class}
# {Pry::CommandSet#command} which creates a BlockCommand or {Pry::CommandSet#create_command}
# which creates a ClassCommand. Please don't use this class directly.
class Command
@ -12,7 +12,7 @@ class Pry
def VOID_VALUE.inspect() "void" end
# Properties of the command itself (as passed as arguments to
# {CommandSet#command} or {CommandSet#command_class}).
# {CommandSet#command} or {CommandSet#create_command}).
class << self
attr_accessor :block
attr_accessor :name
@ -331,7 +331,7 @@ class Pry
# This class implements the bare-minimum functionality that a command should have,
# namely a --help switch, and then delegates actual processing to its subclasses.
#
# Create subclasses using {Pry::CommandSet#command_class}, and override the {options(opt)} method
# Create subclasses using {Pry::CommandSet#create_command}, and override the {options(opt)} method
# to set up an instance of Slop, and the {process} method to actually run the command. If
# necessary, you can also override {setup} which will be called before {options}, for example to
# require any gems your command needs to run, or to set up state.

View file

@ -122,7 +122,6 @@ class Pry
commands[name].class_eval(&block)
commands[name]
end
alias_method :command_class, :create_command
# Execute a block of code before a command is invoked. The block also
# gets access to parameters that will be passed to the command and

View file

@ -30,7 +30,7 @@ class Pry
end
alias_command "file-mode", "shell-mode"
command_class "save-file", "Export to a file using content from the REPL." do
create_command "save-file", "Export to a file using content from the REPL." do
banner <<-USAGE
Usage: save-file [OPTIONS] [METH]
Save REPL content to a file.

View file

@ -9,7 +9,7 @@ describe "Pry::Command" do
describe 'call_safely' do
it 'should display a message if gems are missing' do
cmd = @set.command_class "ford-prefect", "From a planet near Beetlegeuse", :requires_gem => %w(ghijkl) do
cmd = @set.create_command "ford-prefect", "From a planet near Beetlegeuse", :requires_gem => %w(ghijkl) do
#
end
@ -17,7 +17,7 @@ describe "Pry::Command" do
end
it 'should abort early if arguments are required' do
cmd = @set.command_class 'arthur-dent', "Doesn't understand Thursdays", :argument_required => true do
cmd = @set.create_command 'arthur-dent', "Doesn't understand Thursdays", :argument_required => true do
#
end
@ -27,7 +27,7 @@ describe "Pry::Command" do
end
it 'should return VOID without keep_retval' do
cmd = @set.command_class 'zaphod-beeblebrox', "Likes pan-Galactic Gargle Blasters" do
cmd = @set.create_command 'zaphod-beeblebrox', "Likes pan-Galactic Gargle Blasters" do
def process
3
end
@ -37,7 +37,7 @@ describe "Pry::Command" do
end
it 'should return the return value with keep_retval' do
cmd = @set.command_class 'tricia-mcmillian', "a.k.a Trillian", :keep_retval => true do
cmd = @set.create_command 'tricia-mcmillian', "a.k.a Trillian", :keep_retval => true do
def process
5
end
@ -47,7 +47,7 @@ describe "Pry::Command" do
end
it 'should call hooks in the right order' do
cmd = @set.command_class 'marvin', "Pained by the diodes in his left side" do
cmd = @set.create_command 'marvin', "Pained by the diodes in his left side" do
def process
output.puts 3 + args[0].to_i
end
@ -73,13 +73,13 @@ describe "Pry::Command" do
# TODO: This strikes me as rather silly...
it 'should return the value from the last hook with keep_retval' do
cmd = @set.command_class 'slartibartfast', "Designs Fjords", :keep_retval => true do
cmd = @set.create_command 'slartibartfast', "Designs Fjords", :keep_retval => true do
def process
22
end
end
@set.after_command 'slartibartfast' do
@set.after_command 'slartibartfast' do
10
end
@ -97,7 +97,7 @@ describe "Pry::Command" do
end
it 'should use slop to generate the help for classy commands' do
@set.command_class 'eddie', "The ship-board computer" do
@set.create_command 'eddie', "The ship-board computer" do
def options(opt)
opt.banner "Over-cheerful, and makes a ticking noise."
end
@ -107,7 +107,7 @@ describe "Pry::Command" do
end
it 'should provide --help for classy commands' do
cmd = @set.command_class 'agrajag', "Killed many times by Arthur" do
cmd = @set.create_command 'agrajag', "Killed many times by Arthur" do
def options(opt)
opt.on :r, :retaliate, "Try to get Arthur back"
end
@ -117,7 +117,7 @@ describe "Pry::Command" do
end
it 'should provide a -h for classy commands' do
cmd = @set.command_class 'zarniwoop', "On an intergalactic cruise, in his office." do
cmd = @set.create_command 'zarniwoop', "On an intergalactic cruise, in his office." do
def options(opt)
opt.on :e, :escape, "Help zaphod escape the Total Perspective Vortex"
end
@ -127,7 +127,7 @@ describe "Pry::Command" do
end
it 'should use the banner provided' do
cmd = @set.command_class 'deep-thought', "The second-best computer ever" do
cmd = @set.create_command 'deep-thought', "The second-best computer ever" do
banner <<-BANNER
Who's merest operational parameters, I am not worthy to compute.
BANNER
@ -148,7 +148,7 @@ describe "Pry::Command" do
}
it 'should capture lots of stuff from the hash passed to new before setup' do
cmd = @set.command_class 'fenchurch', "Floats slightly off the ground" do
cmd = @set.create_command 'fenchurch', "Floats slightly off the ground" do
define_method(:setup) do
self.context.should == context
target.should == context[:target]
@ -170,7 +170,7 @@ describe "Pry::Command" do
describe 'classy api' do
it 'should call setup, then options, then process' do
cmd = @set.command_class 'rooster', "Has a tasty towel" do
cmd = @set.create_command 'rooster', "Has a tasty towel" do
def setup
output.puts "setup"
end
@ -188,7 +188,7 @@ describe "Pry::Command" do
end
it 'should raise a command error if process is not overridden' do
cmd = @set.command_class 'jeltz', "Commander of a Vogon constructor fleet" do
cmd = @set.create_command 'jeltz', "Commander of a Vogon constructor fleet" do
def proccces
#
end
@ -200,7 +200,7 @@ describe "Pry::Command" do
end
it 'should work if neither options, nor setup is overridden' do
cmd = @set.command_class 'wowbagger', "Immortal, insulting.", :keep_retval => true do
cmd = @set.create_command 'wowbagger', "Immortal, insulting.", :keep_retval => true do
def process
5
end
@ -210,7 +210,7 @@ describe "Pry::Command" do
end
it 'should provide opts and args as provided by slop' do
cmd = @set.command_class 'lintilla', "One of 800,000,000 clones" do
cmd = @set.create_command 'lintilla', "One of 800,000,000 clones" do
def options(opt)
opt.on :f, :four, "A numeric four", :as => Integer, :optional => true
end
@ -225,7 +225,7 @@ describe "Pry::Command" do
end
it 'should allow overriding options after definition' do
cmd = @set.command_class /number-(one|two)/, "Lieutenants of the Golgafrinchan Captain", :shellwords => false do
cmd = @set.create_command /number-(one|two)/, "Lieutenants of the Golgafrinchan Captain", :shellwords => false do
command_options :listing => 'number-one'
end

View file

@ -501,7 +501,7 @@ describe Pry::CommandSet do
end
it 'should return Result.new(true, VOID) if the command is not keep_retval' do
@set.command_class('mrs-cake') do
@set.create_command('mrs-cake') do
def process; 42; end
end
@ -512,7 +512,7 @@ describe Pry::CommandSet do
end
it 'should return Result.new(true, retval) if the command is keep_retval' do
@set.command_class('magrat', 'the maiden', :keep_retval => true) do
@set.create_command('magrat', 'the maiden', :keep_retval => true) do
def process; 42; end
end
@ -529,7 +529,7 @@ describe Pry::CommandSet do
:output => StringIO.new,
:target => binding
}
@set.command_class('agnes') do
@set.create_command('agnes') do
define_method(:process) do
eval_string.should == ctx[:eval_string]
output.should == ctx[:output]
@ -543,7 +543,7 @@ describe Pry::CommandSet do
it 'should add command_set to context' do
set = @set
@set.command_class(/nann+y ogg+/) do
@set.create_command(/nann+y ogg+/) do
define_method(:process) do
command_set.should == set
end