Sha256: ca56ea38e63d41a4164a855eb4affd654c98010e9dcba2db92a5e6d6f3e8f319

Contents?: true

Size: 2 KB

Versions: 12

Compression:

Stored size: 2 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("--no-color", "Start session without syntax highlighting.") do 
    Pry.color = false
  end

  opts.on("--simple-prompt", "Simple prompt mode.") do 
    Pry.prompt = Pry::SIMPLE_PROMPT
  end

  opts.on("-I LOADPATH", "Specify $LOAD_PATH directory.") do  |load_path|
    $LOAD_PATH << load_path
  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.parse!

# invoked via cli
Pry.cli = true

class Pry::Commands
  command "reset", "Reset the REPL to a clean state." do
    output.puts "Pry reset."
    exec("pry")
  end
end

# load ~/.pryrc, if not suppressed with -f option
Pry.should_load_rc = false if !options[:loadrc]

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

# run code passed with `-e`, if there is any.
if options[:code]
  Pry.new(:input => StringIO.new(options[:code]), :print => proc {}).rep(context)
end

# start the session
context.pry

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
pry-0.8.0pre9-i386-mswin32 bin/pry
pry-0.8.0pre9-i386-mingw32 bin/pry
pry-0.8.0pre9-java bin/pry
pry-0.8.0pre9 bin/pry
pry-0.8.0pre8 bin/pry
pry-0.8.0pre8-java bin/pry
pry-0.8.0pre8-i386-mswin32 bin/pry
pry-0.8.0pre8-i386-mingw32 bin/pry
pry-0.8.0pre7 bin/pry
pry-0.8.0pre7-java bin/pry
pry-0.8.0pre7-i386-mswin32 bin/pry
pry-0.8.0pre7-i386-mingw32 bin/pry