Skip to content

Commit

Permalink
show-doc now supports -l and -b options
Browse files Browse the repository at this point in the history
  • Loading branch information
banister committed Jan 23, 2012
1 parent 347e766 commit 110aeaf
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions lib/pry/default_commands/documentation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ def process

def options(opt)
method_options(opt)
opt.on :l, "line-numbers", "Show line numbers."
opt.on :b, "base-one", "Show line numbers but start numbering at 1 (useful for `amend-line` and `play` commands)."
opt.on :f, :flood, "Do not use a pager to view text longer than one screen."
end

Expand All @@ -39,8 +41,22 @@ def process
output.puts "#{text.bold("Signature:")} #{meth.signature}"
output.puts

if opts.present?(:b) || opts.present?(:l)
doc = Code.new(doc, start_line, :text).
with_line_numbers(true)
end

render_output(doc, opts)
end

def start_line
if opts.present?(:'base-one')
1
else
(method_object.source_line - method_object.doc.lines.count) || 1
end
end

end

alias_command "?", "show-doc"
Expand Down Expand Up @@ -81,7 +97,7 @@ def process
e.g: gist -d my_method
e.g: gist -i 1..10
e.g: gist -c show-method
e.g gist -m hello_world --lines 2..-2
e.g: gist -m hello_world --lines 2..-2
USAGE

attr_accessor :content
Expand All @@ -100,7 +116,7 @@ def options(opt)
self.code_type = meth.source_type
end
opt.on :d, :doc, "Gist a method's documentation.", true do |meth_name|
meth = get_method_or_raise(opts[:d], target, {})
meth = get_method_or_raise(meth_name, target, {})
text.no_color do
self.content << process_comment_markup(meth.doc, self.code_type)
end
Expand Down Expand Up @@ -163,11 +179,6 @@ def perform_gist
end
end

def restrict_to_lines(content, lines)
line_range = one_index_range(lines)
content.lines.to_a[line_range].join
end

def gist_file_extension(file_name)
file_name.split(".").last
end
Expand Down

0 comments on commit 110aeaf

Please sign in to comment.