class Pry::CLI
Manage the processing of command line options
Constants
- NoOptionsError
Attributes
input_args[RW]
@return [Array<String>] The input array of strings to process
as CLI options.
option_processors[RW]
@return [Array] The Procs that process the parsed options. Plugins can
utilize this facility in order to add and process their own Pry options.
options[RW]
@return [Proc] The Proc defining the valid command line options.
Public Class Methods
add_option_processor(&block)
click to toggle source
Add a block responsible for processing parsed options.
# File lib/pry/cli.rb, line 44 def add_option_processor(&block) self.option_processors ||= [] option_processors << block self end
add_options(&block)
click to toggle source
add_plugin_options()
click to toggle source
Bring in options defined in plugins
# File lib/pry/cli.rb, line 35 def add_plugin_options Pry.plugins.values.each do |plugin| plugin.load_cli_options end self end
parse_options(args = ARGV)
click to toggle source
# File lib/pry/cli.rb, line 57 def parse_options(args = ARGV) unless options raise NoOptionsError, "No command line options defined! Use Pry::CLI.add_options to add command line options." end self.input_args = args begin opts = Pry::Slop.parse!( args, help: true, multiple_switches: false, strict: true, &options ) rescue Pry::Slop::InvalidOptionError # Display help message on unknown switches and exit. puts Pry::Slop.new(&options) exit end Pry.initial_session_setup Pry.final_session_setup # Option processors are optional. if option_processors option_processors.each { |processor| processor.call(opts) } end opts end
reset()
click to toggle source
Clear `options` and `option_processors`
# File lib/pry/cli.rb, line 52 def reset self.options = nil self.option_processors = nil end
start(opts)
click to toggle source
# File lib/pry/cli.rb, line 89 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])) Pry.final_session_setup 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