`ls` now staggers large output. changed `gem` command to more
restricted `gem-install`, using File.writable? to determine when to use `sudo` instead of rescuing exception. Now outputs Method#parameters info for the `stat` command. Reverted command using 'system' back to using `run`, as `run` might intercept certain commands to provide extra functionality (e.g `cd`)
This commit is contained in:
parent
21a6cc66d4
commit
413507d8dd
|
@ -61,35 +61,33 @@ class Pry
|
||||||
alias_command "quit-program", "exit-program", ""
|
alias_command "quit-program", "exit-program", ""
|
||||||
alias_command "!!!", "exit-program", ""
|
alias_command "!!!", "exit-program", ""
|
||||||
|
|
||||||
command "gem", "gem stuff" do |*args|
|
command "gem-install", "gem stuff" do |gem_name|
|
||||||
if args.first == "install"
|
gem_home = Gem.instance_variable_get(:@gem_home)
|
||||||
gem_name = args[1]
|
output.puts "Attempting to install gem: #{bold(gem_name)}"
|
||||||
output.puts "Attempting to install gem: #{bold(gem_name)}"
|
|
||||||
begin
|
begin
|
||||||
|
if File.writable?(gem_home)
|
||||||
Gem::DependencyInstaller.new.install(gem_name)
|
Gem::DependencyInstaller.new.install(gem_name)
|
||||||
output.puts "Gem #{bold(gem_name)} successfully installed."
|
output.puts "Gem #{bold(gem_name)} successfully installed."
|
||||||
rescue Gem::GemNotFoundException
|
else
|
||||||
output.puts "Required Gem: #{bold(gem_name)} not found."
|
if system("sudo gem install #{gem_name}")
|
||||||
next
|
|
||||||
rescue Gem::FilePermissionError
|
|
||||||
output.puts "FilePermissionError, trying `sudo`..."
|
|
||||||
if system("sudo gem", *args)
|
|
||||||
output.puts "Gem #{bold(gem_name)} successfully installed."
|
output.puts "Gem #{bold(gem_name)} successfully installed."
|
||||||
else
|
else
|
||||||
output.puts "Gem #{bold(gem_name)} could not be installed."
|
output.puts "Gem #{bold(gem_name)} could not be installed."
|
||||||
next
|
next
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
rescue Gem::GemNotFoundException
|
||||||
Gem.refresh
|
output.puts "Required Gem: #{bold(gem_name)} not found."
|
||||||
output.puts "Refreshed gem cache."
|
next
|
||||||
else
|
|
||||||
system "gem", *args
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Gem.refresh
|
||||||
|
output.puts "Refreshed gem cache."
|
||||||
end
|
end
|
||||||
|
|
||||||
command "ri", "View ri documentation. e.g `ri Array#each`" do |*args|
|
command "ri", "View ri documentation. e.g `ri Array#each`" do |*args|
|
||||||
system "ri", *args
|
run ".ri", *args
|
||||||
end
|
end
|
||||||
|
|
||||||
command "stat", "View method information and set _file_ and _dir_ locals" do |*args|
|
command "stat", "View method information and set _file_ and _dir_ locals" do |*args|
|
||||||
|
@ -141,6 +139,12 @@ e.g: stat hello_method
|
||||||
output.puts bold("Method Language: ") + code_type.to_s.capitalize
|
output.puts bold("Method Language: ") + code_type.to_s.capitalize
|
||||||
output.puts bold("Method Type: ") + (meth.is_a?(Method) ? "Bound" : "Unbound")
|
output.puts bold("Method Type: ") + (meth.is_a?(Method) ? "Bound" : "Unbound")
|
||||||
output.puts bold("Method Arity: ") + meth.arity.to_s
|
output.puts bold("Method Arity: ") + meth.arity.to_s
|
||||||
|
|
||||||
|
name_map = { :req => "Required:", :opt => "Optional:", :rest => "Rest:" }
|
||||||
|
if meth.respond_to?(:parameters)
|
||||||
|
output.puts bold("Method Parameters: ") + meth.parameters.group_by(&:first).
|
||||||
|
map { |k, v| "#{name_map[k]} #{v.map { |kk, vv| vv ? vv.to_s : "noname" }.join(", ")}" }.join(". ")
|
||||||
|
end
|
||||||
output.puts bold("Comment length: ") + (doc.empty? ? 'No comment.' : (doc.lines.count.to_s + ' lines.'))
|
output.puts bold("Comment length: ") + (doc.empty? ? 'No comment.' : (doc.lines.count.to_s + ' lines.'))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -387,6 +391,10 @@ Shows local and instance variables by default.
|
||||||
options[:v] = true
|
options[:v] = true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
opts.on("-f", "--flood", "Do not use a pager to view text longer than one screen.") do
|
||||||
|
options[:f] = true
|
||||||
|
end
|
||||||
|
|
||||||
opts.on_tail("-h", "--help", "Show this message.") do
|
opts.on_tail("-h", "--help", "Show this message.") do
|
||||||
output.puts opts
|
output.puts opts
|
||||||
options[:h] = true
|
options[:h] = true
|
||||||
|
@ -454,30 +462,43 @@ Shows local and instance variables by default.
|
||||||
info["constants"] = [Array(target_self.is_a?(Module) ? target.eval("constants(#{csuper})") :
|
info["constants"] = [Array(target_self.is_a?(Module) ? target.eval("constants(#{csuper})") :
|
||||||
target.eval("self.class.constants(#{csuper})")).uniq.sort, i += 1] if options[:c] || options[:a]
|
target.eval("self.class.constants(#{csuper})")).uniq.sort, i += 1] if options[:c] || options[:a]
|
||||||
|
|
||||||
|
text = ""
|
||||||
|
|
||||||
# verbose output?
|
# verbose output?
|
||||||
if options[:v]
|
if options[:v]
|
||||||
|
|
||||||
# verbose
|
# verbose
|
||||||
|
|
||||||
info.sort_by { |k, v| v.last }.each do |k, v|
|
info.sort_by { |k, v| v.last }.each do |k, v|
|
||||||
if !v.first.empty?
|
if !v.first.empty?
|
||||||
output.puts "#{k}:\n--"
|
text << "#{k}:\n--\n"
|
||||||
if Pry.color
|
if Pry.color
|
||||||
output.puts CodeRay.scan(Pry.view(v.first), :ruby).term
|
text << CodeRay.scan(Pry.view(v.first), :ruby).term + "\n"
|
||||||
else
|
else
|
||||||
output.puts Pry.view(v.first)
|
text << Pry.view(v.first) + "\n"
|
||||||
end
|
end
|
||||||
output.puts
|
text << "\n\n"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if !options[:f]
|
||||||
|
stagger_output(text)
|
||||||
|
else
|
||||||
|
output.puts text
|
||||||
|
end
|
||||||
|
|
||||||
# plain
|
# plain
|
||||||
else
|
else
|
||||||
list = info.values.sort_by(&:last).map(&:first).inject(&:+)
|
list = info.values.sort_by(&:last).map(&:first).inject(&:+)
|
||||||
list.uniq! if list
|
list.uniq! if list
|
||||||
if Pry.color
|
if Pry.color
|
||||||
output.puts CodeRay.scan(Pry.view(list), :ruby).term
|
text << CodeRay.scan(Pry.view(list), :ruby).term + "\n"
|
||||||
else
|
else
|
||||||
output.puts Pry.view(list)
|
text << Pry.view(list) + "\n"
|
||||||
|
end
|
||||||
|
if !options[:f]
|
||||||
|
stagger_output(text)
|
||||||
|
else
|
||||||
|
output.puts text
|
||||||
end
|
end
|
||||||
list
|
list
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue