Class: Solanum::Source::Command

Inherits:
Solanum::Source show all
Defined in:
lib/solanum/source.rb

Instance Attribute Summary

Attributes inherited from Solanum::Source

#config, #matchers

Instance Method Summary collapse

Methods inherited from Solanum::Source

#collect, #initialize

Constructor Details

This class inherits a constructor from Solanum::Source

Instance Method Details

#read_input!Object



87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/solanum/source.rb', line 87

def read_input!
  # Locate absolute command path.
  command, args = @config.split(/\s/, 2)
  abs_command =
    if ::File.executable? command
      command
    else
      %x{which #{command} 2> /dev/null}.chomp
    end

  # Check that command exists and is executable.
  raise "Command #{command} not found" unless ::File.exist? abs_command
  raise "Command #{abs_command} not executable" unless ::File.executable? abs_command

  # Run command for output.
  input = %x{#{abs_command} #{args}}
  raise "Error executing command: #{abs_command} #{args}" unless $?.success?

  input
end