Sha256: 433f20cd8d588763d637c8143b5a59bf7a69a42a4684ee44ed72e6c70e51fe56

Contents?: true

Size: 1.64 KB

Versions: 2

Compression:

Stored size: 1.64 KB

Contents

#!/usr/bin/env ruby

# (C) John Mair (banisterfiend)
# MIT license

begin
  require 'pry'
rescue LoadError
  require 'rubygems'
  require 'pry'
end
require 'optparse'

# defaults
options = {
  :context_string => "TOPLEVEL_BINDING",
  :loadrc => true
}

OptionParser.new do |opts|
  opts.banner = %{Usage: pry [OPTIONS] 
Start a Pry session.
See: `https://github.com/banister` for more information.
--
}
  opts.on("-r", "--require FILE", "`require` a Ruby script at startup.") do |file|
    require file
  end

  opts.on("-e", "--exec CODE", "A line of Ruby code to execute in context before the session starts.") do |code|
    options[:code] = code
  end

  opts.on("-f", "Suppress loading of ~/.pryrc") do 
    options[:loadrc] = false
  end

  opts.on("-v", "--version", "Display the Pry version.") do
    puts "Pry version #{Pry::VERSION} on Ruby #{RUBY_VERSION}"
    exit
  end

  opts.on("-c", "--context CONTEXT",
          "Start the session in the specified context. Equivalent to `context.pry` in a session.") do |context|

    # save the context name
    options[:context_string] = context
  end

  opts.on_tail("-h", "--help", "This message.") do 
    puts opts
    exit
  end
end.permute!

rcpath = File.expand_path("~/.pryrc")

# load ~/.pryrc, if not suppressed with -f option
load rcpath if File.exists?(rcpath) && options[:loadrc]

# create the actual context
context = Pry.binding_for(eval(options[:context_string]))

# execute line of code, if provided with -e option
if options[:code]
  result = context.eval(options[:code])
  puts "=> #{Pry.view(result)}"
end

# start the session
context.pry

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
pry-0.5.9 bin/pry
pry-0.5.8 bin/pry