def options(opt)
opt.on :login, "Authenticate the jist gem with GitHub"
opt.on :m, :method, "Gist a method's source.", :argument => true do |meth_name|
meth = get_method_or_raise(meth_name, target, {})
self.content << meth.source << "\n"
self.filename = meth.source_file
end
opt.on :d, :doc, "Gist a method's documentation.", :argument => true do |meth_name|
meth = get_method_or_raise(meth_name, target, {})
text.no_color do
self.content << process_comment_markup(meth.doc) << "\n"
end
self.filename = meth.source_file + ".doc"
end
opt.on :k, :command, "Gist a command's source.", :argument => true do |command_name|
command = find_command(command_name)
block = Pry::Method.new(command.block)
self.content << block.source << "\n"
self.filename = block.source_file
end
opt.on :c, :class, "Gist a class or module's source.", :argument => true do |class_name|
mod = Pry::WrappedModule.from_str(class_name, target)
self.content << mod.source << "\n"
self.filename = mod.source_file
end
opt.on :var, "Gist a variable's content.", :argument => true do |variable_name|
begin
obj = target.eval(variable_name)
rescue Pry::RescuableException
raise CommandError, "Gist failed: Invalid variable name: #{variable_name}"
end
self.content << Pry.config.gist.inspecter.call(obj) << "\n"
end
opt.on :hist, "Gist a range of Readline history lines.", :optional_argument => true, :as => Range, :default => -20..-1 do |range|
h = Pry.history.to_a
self.content << h[one_index_range(convert_to_range(range))].join("\n") << "\n"
end
opt.on :f, :file, "Gist a file.", :argument => true do |file|
self.content << File.read(File.expand_path(file)) << "\n"
self.filename = file
end
opt.on :o, :out, "Gist entries from Pry's output result history. Takes an index or range.", :optional_argument => true,
:as => Range, :default => -1 do |range|
range = convert_to_range(range)
range.each do |v|
self.content << Pry.config.gist.inspecter.call(_pry_.output_array[v])
end
self.content << "\n"
end
opt.on :clip, "Copy the selected content to clipboard instead, do NOT gist it.", :default => false
opt.on :p, :public, "Create a public gist (default: false)", :default => false
opt.on :l, :lines, "Only gist a subset of lines from the gistable content.", :optional_argument => true, :as => Range, :default => 1..-1
opt.on :i, :in, "Gist entries from Pry's input expression history. Takes an index or range.", :optional_argument => true,
:as => Range, :default => -1 do |range|
range = convert_to_range(range)
input_expressions = _pry_.input_array[range] || []
Array(input_expressions).each_with_index do |code, index|
corrected_index = index + range.first
if code && code != ""
self.content << code
if code !~ /;\Z/
self.content << "#{comment_expression_result_for_gist(Pry.config.gist.inspecter.call(_pry_.output_array[corrected_index]))}"
end
end
end
end
end