Class: Availability::CLI

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

Overview

Command-line interface exposed by the installed particle executable.

Constant Summary collapse

SUCCESS =
0
ERROR =
1
USAGE_ERROR =
2

Instance Method Summary collapse

Constructor Details

#initialize(args:, output: $stdout, error: $stderr, env: ENV, working_directory: Dir.pwd, random_path: -> { SecureRandom.hex(12) }) ⇒ CLI

Returns a new instance of CLI.



13
14
15
16
17
18
19
20
21
# File 'lib/availability/cli.rb', line 13

def initialize(args:, output: $stdout, error: $stderr, env: ENV, working_directory: Dir.pwd,
               random_path: -> { SecureRandom.hex(12) })
  @args = args.dup
  @output = output
  @error = error
  @env = env
  @working_directory = working_directory
  @random_path = random_path
end

Instance Method Details

#runObject



23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/availability/cli.rb', line 23

def run
  dispatch(@args.shift)
rescue OptionParser::ParseError => e
  @error.puts(e.message)
  USAGE_ERROR
rescue Availability::Error => e
  @error.puts(e.message)
  ERROR
rescue StandardError => e
  @error.puts("Particle failed unexpectedly (#{e.class}).")
  ERROR
end