Class: Permpress::Command

Inherits:
Object
  • Object
show all
Defined in:
lib/permpress/command.rb

Overview

Generic command interface to execute a command with it’s arguments, pipe the output, and exit correctly.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(executable, files, options = []) ⇒ Command

Returns a new instance of Command.



9
10
11
12
13
# File 'lib/permpress/command.rb', line 9

def initialize(executable, files, options = [])
  @executable = executable
  @files = files
  @options = options
end

Instance Attribute Details

#executableObject (readonly)

Returns the value of attribute executable.



7
8
9
# File 'lib/permpress/command.rb', line 7

def executable
  @executable
end

#filesObject (readonly)

Returns the value of attribute files.



7
8
9
# File 'lib/permpress/command.rb', line 7

def files
  @files
end

#optionsObject (readonly)

Returns the value of attribute options.



7
8
9
# File 'lib/permpress/command.rb', line 7

def options
  @options
end

Instance Method Details

#commandObject Also known as: to_s



27
28
29
# File 'lib/permpress/command.rb', line 27

def command
  "#{executable} #{flags} #{arguments} 2>&1"
end

#run(io = $stdout) ⇒ Object



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

def run(io = $stdout)
  Bundler.with_clean_env do
    Open3.popen3(command) do |_, stdout, _, thread|
      stdout.each do |line|
        io.puts line
      end

      exit thread.value.exitstatus
    end
  end
end