summaryrefslogtreecommitdiff
path: root/bin/pry
blob: e09094676500622d76ef74cb2df4295a38e51cdc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/usr/bin/env ruby

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

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

opts = Slop.parse do
  banner %{Usage: pry [OPTIONS]
Start a Pry session.
See: `https://github.com/banister` for more information.
--
}

  on :e, :exec, "A line of code to execute in context before the session starts", true
  on :f, "Suppress loading of ~/.pryrc"
  on "no-color", "Disable syntax highlighting for session"

  on "simple-prompt", "Enable simple prompt mode" do
    Pry.prompt = Pry::SIMPLE_PROMPT
  end

  on :r, :require, "`require` a Ruby script at startup", true do |file|
    require file
  end

  on :I, "Add a path to the $LOAD_PATH", true do |path|
    $LOAD_PATH << path
  end

  on :v, :version, "Display the Pry version" do
    puts "Pry version #{Pry::VERSION} on Ruby #{RUBY_VERSION}"
    exit
  end

  on(:c, :context,
    "Start the session in the specified context. Equivalent to `context.pry` in a session.",
    true,
    :default => "TOPLEVEL_BINDING"
    )

  on :h, :help, "This message" do
    puts help
    exit
  end
end

# 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 = !opts.f?

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

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

# start the session
context.pry