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 Instance Methods

add_option_processor(&block) click to toggle source

Add a block responsible for processing parsed options.

# File lib/pry/cli.rb, line 47
def add_option_processor(&block)
  self.option_processors ||= []
  option_processors << block

  self
end
add_options(&block) click to toggle source

Add another set of CLI options (a Slop block)

# File lib/pry/cli.rb, line 23
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
add_plugin_options() click to toggle source

Bring in options defined in plugins

# File lib/pry/cli.rb, line 38
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 60
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 = Slop.parse!(
      args,
      :help => true,
      :multiple_switches => false,
      :strict => true,
      &options
    )
  rescue Slop::InvalidOptionError
    # Display help message on unknown switches and exit.
    puts Slop.new(&options)
    exit
  end

  # Option processors are optional.
  if option_processors
    option_processors.each { |processor| processor.call(opts) }
  end

  self
end
reset() click to toggle source

Clear `options` and `option_processors`

# File lib/pry/cli.rb, line 55
def reset
  self.options           = nil
  self.option_processors = nil
end