summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRicho Healey <richo@psych0tik.net>2015-03-11 13:53:21 -0700
committerRicho Healey <richo@psych0tik.net>2015-03-11 13:56:53 -0700
commitf3339c8cef6a4a73f540930d7b48a2ffe6f9352e (patch)
tree58b25b1db5bc967f14f5f8b66bb0ea84fd2ac1d6
parent65fdcba0d97f2c325909454f000ce7dfbc772b2f (diff)
downloadpry-f3339c8cef6a4a73f540930d7b48a2ffe6f9352e.tar.gz
cli: parse_opts should not actually spin off a repl
-rwxr-xr-xbin/pry3
-rw-r--r--lib/pry/cli.rb54
-rw-r--r--lib/pry/config/default.rb3
3 files changed, 31 insertions, 29 deletions
diff --git a/bin/pry b/bin/pry
index 3904fe96..dcd643fb 100755
--- a/bin/pry
+++ b/bin/pry
@@ -13,4 +13,5 @@ rescue LoadError
end
# Process command line options and run Pry
-Pry::CLI.parse_options
+opts = Pry::CLI.parse_options
+Pry::CLI.start(opts)
diff --git a/lib/pry/cli.rb b/lib/pry/cli.rb
index 32040956..7aef2844 100644
--- a/lib/pry/cli.rb
+++ b/lib/pry/cli.rb
@@ -83,7 +83,31 @@ class Pry
option_processors.each { |processor| processor.call(opts) }
end
- self
+ opts
+ end
+
+ def start(opts)
+ exit if opts.help?
+
+ # invoked via cli
+ Pry.cli = true
+
+ # create the actual context
+ if opts[:context]
+ Pry.initial_session_setup
+ context = Pry.binding_for(eval(opts[:context]))
+ else
+ context = Pry.toplevel_binding
+ end
+
+ if Pry::CLI.input_args.any? && Pry::CLI.input_args != ["pry"]
+ full_name = File.expand_path(Pry::CLI.input_args.first)
+ Pry.load_file_through_repl(full_name)
+ exit
+ end
+
+ # Start the session (running any code passed with -e, if there is any)
+ Pry.start(context, :input => StringIO.new(Pry.config.exec_string))
end
end
@@ -93,9 +117,6 @@ class Pry
end
-# String that is built to be executed on start (created by -e and -exec switches)
-exec_string = ""
-
# Bring in options defined by plugins
Slop.new do
on "no-plugins" do
@@ -116,7 +137,7 @@ Copyright (c) 2013 John Mair (banisterfiend)
--
}
on :e, :exec=, "A line of code to execute in context before the session starts" do |input|
- exec_string + input + "\n"
+ Pry.config.exec_string += input + "\n"
end
on "no-pager", "Disable pager for long output" do
@@ -194,27 +215,4 @@ Copyright (c) 2013 John Mair (banisterfiend)
"Start the session in the specified context. Equivalent to `context.pry` in a session.",
:default => "Pry.toplevel_binding"
)
-end.add_option_processor do |opts|
-
- exit if opts.help?
-
- # invoked via cli
- Pry.cli = true
-
- # create the actual context
- if opts[:context]
- Pry.initial_session_setup
- context = Pry.binding_for(eval(opts[:context]))
- else
- context = Pry.toplevel_binding
- end
-
- if Pry::CLI.input_args.any? && Pry::CLI.input_args != ["pry"]
- full_name = File.expand_path(Pry::CLI.input_args.first)
- Pry.load_file_through_repl(full_name)
- exit
- end
-
- # Start the session (running any code passed with -e, if there is any)
- Pry.start(context, :input => StringIO.new(exec_string))
end
diff --git a/lib/pry/config/default.rb b/lib/pry/config/default.rb
index db4d8aac..4dd2eaa4 100644
--- a/lib/pry/config/default.rb
+++ b/lib/pry/config/default.rb
@@ -110,6 +110,9 @@ class Pry::Config::Default
completer: proc {
require "pry/input_completer"
Pry::InputCompleter
+ },
+ exec_string: proc {
+ ""
}
}