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
#initialize(input, output, argv) ⇒ CLI
Initialize the CLI object.
12 13 14 15 16 17 18 19 |
# File 'lib/peeek/cli.rb', line 12 def initialize(input, output, argv) @input = input @output = output = Options.new(argv) rescue Help => e output.puts(e.) exit end |
Instance Attribute Details
#options ⇒ Peeek::CLI::Options (readonly)
23 24 25 |
# File 'lib/peeek/cli.rb', line 23 def 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 = .external_encoding Encoding.default_internal = .internal_encoding end $DEBUG = .debug $VERBOSE = .verbose Dir.chdir(.working_directory) if .working_directory $LOAD_PATH.unshift(*.directories_to_load) .required_libraries.each(&method(:require)) hook_targets = materialize_hook_targets(binding) process = setup_to_execute(binding) @output.puts("peeek-#{VERSION}") if .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 |