Class: Githuh::CLI::Launcher

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(argv, stdin = STDIN, stdout = STDOUT, stderr = STDERR, kernel = nil) ⇒ Launcher

Returns a new instance of Launcher.



13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/githuh/cli/launcher.rb', line 13

def initialize(argv, stdin = STDIN, stdout = STDOUT, stderr = STDERR, kernel = nil)
  if ::Githuh.launcher
    raise(ArgumentError, "Another instance of CLI Launcher was detected, aborting.")
  else
    Githuh.launcher = self
  end

  self.argv   = argv
  self.stdin  = stdin
  self.stdout = stdout
  self.stderr = stderr
  self.kernel = kernel
end

Instance Attribute Details

#argvObject

Returns the value of attribute argv.



11
12
13
# File 'lib/githuh/cli/launcher.rb', line 11

def argv
  @argv
end

#commandObject

Returns the value of attribute command.



11
12
13
# File 'lib/githuh/cli/launcher.rb', line 11

def command
  @command
end

#kernelObject

Returns the value of attribute kernel.



11
12
13
# File 'lib/githuh/cli/launcher.rb', line 11

def kernel
  @kernel
end

#stderrObject

Returns the value of attribute stderr.



11
12
13
# File 'lib/githuh/cli/launcher.rb', line 11

def stderr
  @stderr
end

#stdinObject

Returns the value of attribute stdin.



11
12
13
# File 'lib/githuh/cli/launcher.rb', line 11

def stdin
  @stdin
end

#stdoutObject

Returns the value of attribute stdout.



11
12
13
# File 'lib/githuh/cli/launcher.rb', line 11

def stdout
  @stdout
end

Instance Method Details

#execute!Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/githuh/cli/launcher.rb', line 27

def execute!
  if argv.empty? || !(%w(--help -h) & argv).empty?
    stdout.puts BANNER
    Githuh.configure_kernel_behavior! help: true
  else
    Githuh.configure_kernel_behavior!
  end

  self.command = ::Dry::CLI.new(::Githuh::CLI::Commands)
  command.call(arguments: argv, out: stdout, err: stderr)

rescue StandardError => e
  box = TTY::Box.frame('ERROR:', ' ', e.message, **BOX_OPTIONS)
  stderr.print box

ensure
  Githuh.restore_kernel_behavior!
  exit(10) unless Githuh.in_test
end