Class: Githuh::CLI::Launcher
- Inherits:
-
Object
- Object
- Githuh::CLI::Launcher
- Defined in:
- lib/githuh/cli/launcher.rb
Instance Attribute Summary collapse
-
#argv ⇒ Object
Returns the value of attribute argv.
-
#command ⇒ Object
Returns the value of attribute command.
-
#kernel ⇒ Object
Returns the value of attribute kernel.
-
#stderr ⇒ Object
Returns the value of attribute stderr.
-
#stdin ⇒ Object
Returns the value of attribute stdin.
-
#stdout ⇒ Object
Returns the value of attribute stdout.
Instance Method Summary collapse
- #execute! ⇒ Object
-
#initialize(argv, stdin = STDIN, stdout = STDOUT, stderr = STDERR, kernel = nil) ⇒ Launcher
constructor
A new instance of Launcher.
- #trace? ⇒ Boolean
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
#argv ⇒ Object
Returns the value of attribute argv.
12 13 14 |
# File 'lib/githuh/cli/launcher.rb', line 12 def argv @argv end |
#command ⇒ Object
Returns the value of attribute command.
12 13 14 |
# File 'lib/githuh/cli/launcher.rb', line 12 def command @command end |
#kernel ⇒ Object
Returns the value of attribute kernel.
12 13 14 |
# File 'lib/githuh/cli/launcher.rb', line 12 def kernel @kernel end |
#stderr ⇒ Object
Returns the value of attribute stderr.
12 13 14 |
# File 'lib/githuh/cli/launcher.rb', line 12 def stderr @stderr end |
#stdin ⇒ Object
Returns the value of attribute stdin.
12 13 14 |
# File 'lib/githuh/cli/launcher.rb', line 12 def stdin @stdin end |
#stdout ⇒ Object
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..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
57 58 59 |
# File 'lib/githuh/cli/launcher.rb', line 57 def trace? argv.include?('-t') || argv.include?('--trace') end |