Class: Pry::CLI

Inherits:
Object show all
Defined in:
lib/pry/cli.rb

Overview

Manage the processing of command line options

Constant Summary

NoOptionsError =
Class.new(StandardError)

Class Attribute Summary (collapse)

Class Method Summary (collapse)

Class Attribute Details

+ (Array) option_processors

The Procs that process the parsed options.

Returns:

  • (Array)

    The Procs that process the parsed options.



15
16
17
# File 'lib/pry/cli.rb', line 15

def option_processors
  @option_processors
end

+ (Proc) options

The Proc defining the valid command line options.

Returns:

  • (Proc)

    The Proc defining the valid command line options.



12
13
14
# File 'lib/pry/cli.rb', line 12

def options
  @options
end

Class Method Details

+ (Object) add_options(&block)

Add another set of CLI options (a Slop block)



18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/pry/cli.rb', line 18

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

+ (Object) add_plugin_options

Bring in options defined in plugins



33
34
35
36
37
38
39
# File 'lib/pry/cli.rb', line 33

def add_plugin_options
  Pry.plugins.values.each do |plugin|
    plugin.load_cli_options
  end

  self
end

+ (Object) parse_options(args = ARGV.dup)

Raises:



55
56
57
58
59
60
61
62
# File 'lib/pry/cli.rb', line 55

def parse_options(args=ARGV.dup)
  raise NoOptionsError, "No command line options defined! Use Pry::CLI.add_options to add command line options." if !options

  opts = Slop.parse(args, :help => true, :multiple_switches => false, &options)
  option_processors.each { |processor| processor.call(opts) } if option_processors # option processors are optional

  self
end

+ (Object) process_options(&block)

Add a block responsible for processing parsed options.



42
43
44
45
46
47
# File 'lib/pry/cli.rb', line 42

def process_options(&block)
  self.option_processors ||= []
  option_processors << block

  self
end

+ (Object) reset

Clear options and option_processors



50
51
52
53
# File 'lib/pry/cli.rb', line 50

def reset
  self.options           = nil
  self.option_processors = nil
end