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.



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

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.



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

def argv
  @argv
end

#commandObject

Returns the value of attribute command.



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

def command
  @command
end

#kernelObject

Returns the value of attribute kernel.



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

def kernel
  @kernel
end

#stderrObject

Returns the value of attribute stderr.



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

def stderr
  @stderr
end

#stdinObject

Returns the value of attribute stdin.



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

def stdin
  @stdin
end

#stdoutObject

Returns the value of attribute stdout.



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

def stdout
  @stdout
end

Instance Method Details

#execute!Object



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
# File 'lib/githuh/cli/launcher.rb', line 28

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
  lines = [e.message.gsub(/\n/, ', ')]
  if e.backtrace
    lines << ''
    lines.concat(e.backtrace)
  end

  box = TTY::Box.frame(*lines,
                       **BOX_OPTIONS.merge(
                         width: TTY::Screen.width,
                         title: { top_center: "#{e.class.name}" },
                       ))
  stderr.puts
  stderr.print box
ensure
  Githuh.restore_kernel_behavior!
  exit(0) unless Githuh.in_test
end

#trace?Boolean

Returns:

  • (Boolean)


57
58
59
# File 'lib/githuh/cli/launcher.rb', line 57

def trace?
  argv.include?('-t') || argv.include?('--trace')
end