Class: Greener::Runner
- Inherits:
-
Object
- Object
- Greener::Runner
- Defined in:
- lib/greener/runner.rb
Overview
Aruba In Process + Thor integration Based on github.com/erikhuda/thor/wiki/Integrating-with-Aruba-In-Process-Runs
Instance Method Summary collapse
- #execute! ⇒ Object
-
#initialize(argv, stdin = STDIN, stdout = STDOUT, stderr = STDERR, kernel = Kernel) ⇒ Runner
constructor
Allow everything fun to be injected from the outside while defaulting to normal implementations.
Constructor Details
#initialize(argv, stdin = STDIN, stdout = STDOUT, stderr = STDERR, kernel = Kernel) ⇒ Runner
Allow everything fun to be injected from the outside while defaulting to normal implementations.
13 14 15 16 17 18 19 |
# File 'lib/greener/runner.rb', line 13 def initialize(argv, stdin = STDIN, stdout = STDOUT, stderr = STDERR, kernel = Kernel) @argv = argv @stdin = stdin @stdout = stdout @stderr = stderr @kernel = kernel end |
Instance Method Details
#execute! ⇒ Object
21 22 23 24 25 26 27 28 29 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 60 61 |
# File 'lib/greener/runner.rb', line 21 def execute! exit_code = begin # Thor accesses these streams directly rather than letting them be injected, so we replace them... $stderr = @stderr $stdin = @stdin $stdout = @stdout # Run our normal Thor app the way we know and love. Greener::CLI.start(@argv) # Thor::Base#start does not have a return value, assume success if no exception is raised. 0 rescue Greener::Error::Standard => e @stderr.puts e. 1 rescue StandardError => e # The ruby interpreter would pipe this to STDERR and exit 1 in the case of an unhandled exception b = e.backtrace @stderr.puts("#{b.shift}: #{e.} (#{e.class})") @stderr.puts(b.map { |s| "\tfrom #{s}" }.join("\n")) 1 rescue SystemExit => e e.status ensure # TODO: reset your app here, free up resources, etc. # Examples: # MyApp.logger.flush # MyApp.logger.close # MyApp.logger = nil # # MyApp.reset_singleton_instance_variables # ...then we put the streams back. $stderr = STDERR $stdin = STDIN $stdout = STDOUT end # Proxy our exit code back to the injected kernel. @kernel.exit(exit_code) end |