Class: Clicoder::ArubaCLI

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

Overview

Instance Method Summary collapse

Constructor Details

#initialize(argv, stdin = STDIN, stdout = STDOUT, stderr = STDERR, kernel = Kernel) ⇒ ArubaCLI

Returns a new instance of ArubaCLI.



157
158
159
# File 'lib/clicoder/cli.rb', line 157

def initialize(argv, stdin=STDIN, stdout=STDOUT, stderr=STDERR, kernel=Kernel)
  @argv, @stdin, @stdout, @stderr, @kernel = argv, stdin, stdout, stderr, kernel
end

Instance Method Details

#execute!Object



161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
# File 'lib/clicoder/cli.rb', line 161

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.
    CLI.start(@argv)

    # Thor::Base#start does not have a return value, assume success if no exception is raised.
    0
  rescue Exception => e
    # Proxy any exception that comes out of Thor itself back to stderr
    $stderr.write(e.message + "\n")

    # Exit with a failure code.
    1
  ensure
    # ...then we put them back.
    $stderr = STDERR
    $stdin = STDERR
    $stdout = STDERR
  end

  # Proxy our exit code back to the injected kernel.
  @kernel.exit(exit_code)
end