Class: Peeek::CLI
- Inherits:
-
Object
- Object
- Peeek::CLI
- Defined in:
- lib/peeek/cli.rb,
lib/peeek/cli/options.rb
Defined Under Namespace
Modules: EncodingOptions Classes: Help, Options
Instance Attribute Summary collapse
-
#options ⇒ Peeek::CLI::Options
readonly
Options to run from CLI.
Instance Method Summary collapse
-
#initialize(input, output, argv) ⇒ CLI
constructor
Initialize the CLI object.
-
#run(binding) ⇒ Peeek::Calls
Run the command or the program file with a binding.
Constructor Details
Instance Attribute Details
#options ⇒ Peeek::CLI::Options (readonly)
Returns options to run from CLI.
23 24 25 |
# File 'lib/peeek/cli.rb', line 23 def @options end |
Instance Method Details
#run(binding) ⇒ Peeek::Calls
Run the command or the program file with a binding. And capture calls that raised when running it.
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/peeek/cli.rb', line 30 def run(binding) if Options. Encoding.default_external = @options.external_encoding Encoding.default_internal = @options.internal_encoding end $DEBUG = @options.debug $VERBOSE = @options.verbose Dir.chdir(@options.working_directory) if @options.working_directory $LOAD_PATH.unshift(*@options.directories_to_load) @options.required_libraries.each(&method(:require)) hook_targets = materialize_hook_targets(binding) process = setup_to_execute(binding) @output.puts("peeek-#{VERSION}") if @options.version_requested? original_stdout = $stdout $stdout = @output begin Peeek.capture(hook_targets, &process) rescue => e e.set_backtrace(e.backtrace.reject { |line| line =~ %r{lib/peeek} }) raise e ensure $stdout = original_stdout end end |