summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--LICENSE25
-rw-r--r--Rakefile7
-rw-r--r--lib/pry/commands.rb17
-rw-r--r--lib/pry/version.rb2
-rw-r--r--test/test.rb36
-rw-r--r--wiki/Customizing-pry.md23
6 files changed, 98 insertions, 12 deletions
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 00000000..d1a50d62
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,25 @@
+License
+-------
+
+(The MIT License)
+
+Copyright (c) 2011 John Mair (banisterfiend)
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+'Software'), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
diff --git a/Rakefile b/Rakefile
index 76a00e84..602642b0 100644
--- a/Rakefile
+++ b/Rakefile
@@ -25,7 +25,7 @@ def apply_spec_defaults(s)
s.homepage = "http://banisterfiend.wordpress.com"
s.has_rdoc = 'yard'
s.files = Dir["ext/**/extconf.rb", "ext/**/*.h", "ext/**/*.c", "lib/**/*.rb",
- "test/*.rb", "CHANGELOG", "README.markdown", "Rakefile", ".gemtest"]
+ "test/*.rb", "CHANGELOG", "LICENSE", "README.markdown", "Rakefile", ".gemtest"]
end
task :test do
@@ -43,6 +43,11 @@ task :pry do
Pry.start
end
+desc "show pry version"
+task :version do
+ puts "Pry version: #{Pry::VERSION}"
+end
+
namespace :ruby do
spec = Gem::Specification.new do |s|
apply_spec_defaults(s)
diff --git a/lib/pry/commands.rb b/lib/pry/commands.rb
index bd3e0129..717e76c0 100644
--- a/lib/pry/commands.rb
+++ b/lib/pry/commands.rb
@@ -76,14 +76,17 @@ class Pry
end
command "show_method", "Show sourcecode for method <methname>." do |meth_name|
- meth_name = target.eval("__method__").to_s if !meth_name
- puts "blah #{meth_name.to_s}"
- doc = target.eval("method(\"#{meth_name}\")").source
- output.puts doc
+ if meth_name
+ meth_name = target.eval("__method__").to_s if !meth_name
+ doc = target.eval("method(\"#{meth_name}\")").source
+ output.puts doc
+ else
+ output.puts "Error: Not in a method."
+ end
end
command "show_imethod", "Show sourcecode for instance method <methname>." do |meth_name|
- doc = target.eval("instance_method(#{meth_name})").source
+ doc = target.eval("instance_method(\"#{meth_name}\")").source
output.puts doc
end
@@ -103,11 +106,11 @@ class Pry
end
command "ls_methods", "List all methods defined on class of receiver." do
- output.puts "#{Pry.view(target.eval('public_methods(false) + private_methods(false) + protected_methods(false)'))}"
+ output.puts "#{Pry.view(target.eval('(public_methods(false) + private_methods(false) + protected_methods(false)).sort'))}"
end
command "ls_imethods", "List all instance methods defined on class of receiver." do
- output.puts "#{Pry.view(target.eval('public_instance_methods(false) + private_instance_methods(false) + protected_instance_methods(false)'))}"
+ output.puts "#{Pry.view(target.eval('(public_instance_methods(false) + private_instance_methods(false) + protected_instance_methods(false)).sort'))}"
end
command ["exit", "quit", "back"], "End the current Pry session." do
diff --git a/lib/pry/version.rb b/lib/pry/version.rb
index d1f763bb..a1263fe8 100644
--- a/lib/pry/version.rb
+++ b/lib/pry/version.rb
@@ -1,3 +1,3 @@
class Pry
- VERSION = "0.4.2pre1"
+ VERSION = "0.4.2"
end
diff --git a/test/test.rb b/test/test.rb
index cd67cfdc..34ac3131 100644
--- a/test/test.rb
+++ b/test/test.rb
@@ -353,8 +353,38 @@ describe Pry do
Object.remove_const(:Command3)
end
+ it 'should alias a command with another command' do
+ class Command6 < Pry::CommandBase
+ alias_command "help2", "help"
+ end
+
+ Command6.commands["help2"].should == Command6.commands["help"]
+ # str_output = StringIO.new
+ # Pry.new(:input => InputTester.new("run_v"), :output => str_output, :commands => Command3).rep
+ # str_output.string.should =~ /v command/
+
+ Object.remove_const(:Command6)
+ end
+
+ it 'should change description of a command using desc' do
+
+ class Command7 < Pry::Commands
+ end
+
+ orig = Command7.commands["help"][:description]
+
+ class Command7
+ desc "help", "blah"
+ end
+
+ Command7.commands["help"][:description].should.not == orig
+ Command7.commands["help"][:description].should == "blah"
+
+ Object.remove_const(:Command7)
+ end
+
it 'should run a command from within a command' do
- class Command3 < Pry::Commands
+ class Command01 < Pry::Commands
command "v" do
output.puts "v command"
end
@@ -365,10 +395,10 @@ describe Pry do
end
str_output = StringIO.new
- Pry.new(:input => InputTester.new("run_v"), :output => str_output, :commands => Command3).rep
+ Pry.new(:input => InputTester.new("run_v"), :output => str_output, :commands => Command01).rep
str_output.string.should =~ /v command/
- Object.remove_const(:Command3)
+ Object.remove_const(:Command01)
end
it 'should enable an inherited method to access opts and output and target, due to instance_exec' do
diff --git a/wiki/Customizing-pry.md b/wiki/Customizing-pry.md
index 23d0828a..a5f9e9aa 100644
--- a/wiki/Customizing-pry.md
+++ b/wiki/Customizing-pry.md
@@ -200,6 +200,28 @@ being invoked:
end
end
+##### `alias_command` method
+
+The `alias_command` method creates an alias of a command. The first
+parameter is the name of the new command, the second parameter is the
+name of the command to be aliased; an optional third parameter is the
+description to use for the alias. If no description is provided then
+the description of the original command is used.
+
+ class MyCommands < Pry::Commands
+ alias_command "help2", "help", "An alias of help"
+ end
+
+##### `desc` method
+
+The `desc` method is used to give a command a new description. The
+first parameter is the name of the command, the second parameter is
+the description.
+
+ class MyCommands < Pry::Commands
+ desc "ls", "a new description"
+ end
+
#### Utility methods for commands
All commands can access the special `output` and `target` methods. The
@@ -372,3 +394,4 @@ exception and precedes the output of a value by the text `"Output is: "`:
end
end
+[Back to front page of documentation](http://rdoc.info/github/banister/pry/master/file/README.markdown)