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 46 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 39 def add_plugin_options Pry.plugins.values.each(&:load_cli_options) self end
parse_options(args = ARGV)
click to toggle source
# File lib/pry/cli.rb, line 59 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 @pass_argv = args.index { |cli_arg| %w[- --].include?(cli_arg) } if @pass_argv slop_args = args[0...@pass_argv] self.input_args = args.replace(args[@pass_argv + 1..-1]) else self.input_args = slop_args = args end begin opts = Pry::Slop.parse!( slop_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) Kernel.exit end Pry.initial_session_setup Pry.final_session_setup # Option processors are optional. option_processors.each { |processor| processor.call(opts) } if option_processors opts end
reset()
click to toggle source
Clear `options` and `option_processors`
# File lib/pry/cli.rb, line 54 def reset self.options = nil self.option_processors = nil end
start(opts)
click to toggle source
# File lib/pry/cli.rb, line 97 def start(opts) Kernel.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])) # rubocop:disable Security/Eval Pry.final_session_setup else context = Pry.toplevel_binding end if !@pass_argv && 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) Kernel.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