From b7d9d8f756d19a50d700c023768661f6f8e6a6b4 Mon Sep 17 00:00:00 2001 From: John Mair Date: Wed, 28 Dec 2011 02:28:21 +1300 Subject: [PATCH] allow multiple -i switches to gist e.g gist -i 1..3 -i 6..7 --- lib/pry/default_commands/documentation.rb | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/lib/pry/default_commands/documentation.rb b/lib/pry/default_commands/documentation.rb index 3e18c014..b9eb5ccd 100644 --- a/lib/pry/default_commands/documentation.rb +++ b/lib/pry/default_commands/documentation.rb @@ -59,6 +59,7 @@ class Pry require 'gist' target = target() + input_ranges = [] opts = parse_options!(args) do |opt| opt.banner unindent <<-USAGE @@ -73,7 +74,9 @@ class Pry opt.on :d, :doc, "Gist a method's documentation.", true opt.on :m, :method, "Gist a method's source.", true opt.on :p, :public, "Create a public gist (default: false)", :default => false - opt.on :i, :in, "Gist entries from Pry's input expression history. Takes an index or range.", :optional => true, :as => Range, :default => -5..-1 + opt.on :i, :in, "Gist entries from Pry's input expression history. Takes an index or range.", :optional => true, :as => Range, :default => -5..-1 do |range| + input_ranges << absolute_index_range(range, _pry_.input_array.length) + end end type_map = { :ruby => "rb", :c => "c", :plain => "plain" } @@ -81,7 +84,7 @@ class Pry code_type = :ruby content = "" normalized_range = absolute_index_range(opts[:i], _pry_.input_array.length) - input_items = _pry_.input_array[normalized_range] || [] + input_items = input_ranges.map { |v| _pry_.input_array[v] || [] }.flatten input_items.each_with_index.map do |code, index| corrected_index = index + normalized_range.first @@ -107,9 +110,9 @@ class Pry # prevent Gist from exiting the session on error begin - link = Gist.write([:extension => ".#{type_map[code_type]}", - :input => content], - !opts[:p]) + link = Gist.write([:extension => ".#{type_map[code_type]}", + :input => content], + !opts[:p]) rescue SystemExit end @@ -119,7 +122,6 @@ class Pry end end - helpers do def comment_expression_result_for_gist(result) content = ""