class Pry::CLI
Manage the processing of command line options
def add_option_processor(&block)
def add_option_processor(&block) self.option_processors ||= [] option_processors << block self end
def add_options(&block)
def add_options(&block) if options old_options = options self.options = proc do instance_exec(&old_options) instance_exec(&block) end else self.options = block end self end
def parse_options(args = ARGV)
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
def reset
def reset self.options = nil self.option_processors = nil end
def start(opts)
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