Sync commands with new API.

This commit is contained in:
Rob Gleeson 2011-05-07 15:26:53 +01:00
parent bec54ce65c
commit a13f71cab5
6 changed files with 26 additions and 26 deletions

View File

@ -55,9 +55,9 @@ class Pry
gems.each do |gem|
begin
if require gem
output.puts "#{bright_yellow(gem)} loaded"
output.puts "#{text.bright_yellow(gem)} loaded"
else
output.puts "#{bright_white(gem)} already loaded"
output.puts "#{text.bright_white(gem)} already loaded"
end
rescue LoadError => e
@ -65,7 +65,7 @@ class Pry
if gem_installed? gem
output.puts e.inspect
else
output.puts "#{bright_red(gem)} not found"
output.puts "#{text.bright_red(gem)} not found"
if prompt("Install the gem?") == "y"
run "gem-install", gem
end

View File

@ -97,7 +97,7 @@ class Pry
end
set_file_and_dir_locals(file)
output.puts "\n#{bold('From:')} #{file} @ line #{line_num} in #{klass}##{meth_name}:\n\n"
output.puts "\n#{text.bold('From:')} #{file} @ line #{line_num} in #{klass}##{meth_name}:\n\n"
# This method inspired by http://rubygems.org/gems/ir_b
File.open(file).each_with_index do |line, index|

View File

@ -80,18 +80,18 @@ e.g: stat hello_method
doc, code_type = doc_and_code_type_for(meth)
output.puts make_header(meth, code_type, code)
output.puts bold("Method Name: ") + meth_name
output.puts bold("Method Owner: ") + (meth.owner.to_s ? meth.owner.to_s : "Unknown")
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 Arity: ") + meth.arity.to_s
output.puts text.bold("Method Name: ") + meth_name
output.puts text.bold("Method Owner: ") + (meth.owner.to_s ? meth.owner.to_s : "Unknown")
output.puts text.bold("Method Language: ") + code_type.to_s.capitalize
output.puts text.bold("Method Type: ") + (meth.is_a?(Method) ? "Bound" : "Unbound")
output.puts text.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).
output.puts text.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 text.bold("Comment length: ") + (doc.empty? ? 'No comment.' : (doc.lines.count.to_s + ' lines.'))
end
command "gist-method", "Gist a method to github. Type `gist-method --help` for more info.", :requires_gem => "gist" do |*args|
@ -128,7 +128,7 @@ e.g: gist -d my_method
content, code_type = code_and_code_type_for(meth)
else
content, code_type = doc_and_code_type_for(meth)
no_color do
text.no_color do
content = process_comment_markup(content, code_type)
end
code_type = :plain

View File

@ -5,22 +5,22 @@ class Pry
command "gem-install", "Install a gem and refresh the gem cache." do |gem_name|
gem_home = Gem.instance_variable_get(:@gem_home)
output.puts "Attempting to install gem: #{bold(gem_name)}"
output.puts "Attempting to install gem: #{text.bold gem_name}"
begin
if File.writable?(gem_home)
Gem::DependencyInstaller.new.install(gem_name)
output.puts "Gem #{bold(gem_name)} successfully installed."
output.puts "Gem #{text.bold gem_name} successfully installed."
else
if system("sudo gem install #{gem_name}")
output.puts "Gem #{bold(gem_name)} successfully installed."
output.puts "Gem #{text.bold gem_name} successfully installed."
else
output.puts "Gem #{bold(gem_name)} could not be installed."
output.puts "Gem #{text.bold gem_name} could not be installed."
next
end
end
rescue Gem::GemNotFoundException
output.puts "Required Gem: #{bold(gem_name)} not found."
output.puts "Required Gem: #{text.bold gem_name} not found."
next
end
@ -45,10 +45,10 @@ class Pry
gems.each do |gemname, specs|
versions = specs.map(&:version).sort.reverse.map(&:to_s)
versions = ["#{bright_green versions.first}"] + versions[1..-1].map{|v| "#{green v}" }
versions = ["#{text.bright_green versions.first}"] + versions[1..-1].map{|v| "#{text.green v}" }
gemname = highlight(gemname, query) if query
output.puts "#{white gemname} (#{grey(versions.join ', ')})"
output.puts "#{text.white gemname} (#{text.grey(versions.join ', ')})"
end
end

View File

@ -113,7 +113,7 @@ e.g: show-command show-method
opts = Slop.parse!(args) do |opts|
opts.banner %{Usage: edit-method [OPTIONS] [METH]
Edit the method METH in an editor.
Ensure #{bold("Pry.editor")} is set to your editor of choice.
Ensure #{text.bold("Pry.editor")} is set to your editor of choice.
e.g: edit-method hello_method
--
}
@ -137,7 +137,7 @@ e.g: edit-method hello_method
next
end
next output.puts "Error: No editor set!\nEnsure that #{bold("Pry.editor")} is set to your editor of choice." if !Pry.editor
next output.puts "Error: No editor set!\nEnsure that #{text.bold("Pry.editor")} is set to your editor of choice." if !Pry.editor
if is_a_c_method?(meth)
output.puts "Error: Can't edit a C method."

View File

@ -26,7 +26,7 @@ class Pry
# if start_line is not false then add line numbers starting with start_line
def render_output(should_flood, start_line, doc)
if start_line
doc = add_line_numbers(doc, start_line)
doc = Pry::Helpers::Text.with_line_numbers doc, start_line
end
if should_flood
@ -124,14 +124,14 @@ class Pry
end
def make_header(meth, code_type, content)
num_lines = "Number of lines: #{bold(content.each_line.count.to_s)}"
num_lines = "Number of lines: #{Pry::Helpers::Text.bold(content.each_line.count.to_s)}"
case code_type
when :ruby
file, line = meth.source_location
"\n#{bold('From:')} #{file} @ line #{line}:\n#{num_lines}\n\n"
"\n#{Pry::Helpers::Text.bold('From:')} #{file} @ line #{line}:\n#{num_lines}\n\n"
else
file = Pry::MethodInfo.info_for(meth).file
"\n#{bold('From:')} #{file} in Ruby Core (C Method):\n#{num_lines}\n\n"
"\n#{Pry::Helpers.Text.bold('From:')} #{file} in Ruby Core (C Method):\n#{num_lines}\n\n"
end
end
@ -225,7 +225,7 @@ class Pry
in_tag_block = nil
output = comment.lines.map do |v|
if in_tag_block && v !~ /^\S/
strip_color_codes(strip_color_codes(v))
Pry::Helpers::Text.strip_color Pry::Helpers::Text.strip_color(v)
elsif in_tag_block
in_tag_block = false
v