Class: Pry::CLI
Overview
Manage the processing of command line options
Constant Summary collapse
- NoOptionsError =
Class.new(StandardError)
Class Attribute Summary collapse
-
.input_args ⇒ Array<String>
The input array of strings to process as CLI options.
-
.option_processors ⇒ Array
The Procs that process the parsed options.
-
.options ⇒ Proc
The Proc defining the valid command line options.
Class Method Summary collapse
-
.add_option_processor(&block) ⇒ Object
Add a block responsible for processing parsed options.
-
.add_options(&block) ⇒ Object
Add another set of CLI options (a Pry::Slop block).
-
.add_plugin_options ⇒ Object
Bring in options defined in plugins.
- .parse_options(args = ARGV) ⇒ Object
-
.reset ⇒ Object
Clear ‘options` and `option_processors`.
- .start(opts) ⇒ Object
Class Attribute Details
.input_args ⇒ Array<String>
Returns The input array of strings to process as CLI options.
20 21 22 |
# File 'lib/pry/cli.rb', line 20 def input_args @input_args end |
.option_processors ⇒ Array
Returns The Procs that process the parsed options. Plugins can utilize this facility in order to add and process their own Pry options.
16 17 18 |
# File 'lib/pry/cli.rb', line 16 def option_processors @option_processors end |
.options ⇒ Proc
Returns The Proc defining the valid command line options.
11 12 13 |
# File 'lib/pry/cli.rb', line 11 def @options end |
Class Method Details
.add_option_processor(&block) ⇒ Object
Add a block responsible for processing parsed options.
47 48 49 50 51 52 |
# File 'lib/pry/cli.rb', line 47 def add_option_processor(&block) self.option_processors ||= [] option_processors << block self end |
.add_options(&block) ⇒ Object
Add another set of CLI options (a Pry::Slop block)
23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/pry/cli.rb', line 23 def (&block) if = self. = proc do instance_exec(&) instance_exec(&block) end else self. = block end self end |
.add_plugin_options ⇒ Object
Bring in options defined in plugins
38 39 40 41 42 43 44 |
# File 'lib/pry/cli.rb', line 38 def Pry.plugins.values.each do |plugin| plugin. end self end |
.parse_options(args = ARGV) ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/pry/cli.rb', line 60 def (args=ARGV) unless raise NoOptionsError, "No command line options defined! Use Pry::CLI.add_options to add command line options." end # Load config files etc first, ensuring that cli options will take precedence. Pry.initial_session_setup self.input_args = args begin opts = Pry::Slop.parse!( args, :help => true, :multiple_switches => false, :strict => true, & ) rescue Pry::Slop::InvalidOptionError # Display help message on unknown switches and exit. puts Pry::Slop.new(&) exit end Pry.final_session_setup # Option processors are optional. if option_processors option_processors.each { |processor| processor.call(opts) } end opts end |
.reset ⇒ Object
Clear ‘options` and `option_processors`
55 56 57 58 |
# File 'lib/pry/cli.rb', line 55 def reset self. = nil self.option_processors = nil end |
.start(opts) ⇒ Object
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/pry/cli.rb', line 94 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.(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 |