Class: Gitw::Exec

Inherits:
Object
  • Object
show all
Defined in:
lib/gitw/exec.rb

Overview

exec

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*commands, **options) ⇒ Exec

Returns a new instance of Exec.



9
10
11
12
# File 'lib/gitw/exec.rb', line 9

def initialize(*commands, **options)
  @commands = commands
  @options = options
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



31
32
33
# File 'lib/gitw/exec.rb', line 31

def options
  @options
end

Instance Method Details

#commandsObject



27
28
29
# File 'lib/gitw/exec.rb', line 27

def commands
  @commands.flatten.compact
end

#execObject



14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/gitw/exec.rb', line 14

def exec
  # puts "EXEC (#{Dir.pwd})> #{commands} #{options}"
  stdout, stderr, exit_status = Open3.capture3(*commands, **options)

  ExecResult.new(commands: commands,
                 options: options,
                 status: exit_status,
                 stdout: stdout,
                 stderr: stderr)
rescue StandardError => e
  ExecResult.from_exception(e, commands: commands, options: options)
end