Module: WebVideo::Tools

Defined in:
lib/web_video/tools.rb

Class Method Summary collapse

Class Method Details

.apply_options(command, options) ⇒ Object



29
30
31
32
33
34
35
36
37
38
# File 'lib/web_video/tools.rb', line 29

def self.apply_options(command, options)
  str = command.dup
  
  options.each do |key, value|
    param = value.is_a?(String) ? value.inspect : value
    str.gsub!("$#{key}$", param.to_s)
  end
  
  str
end

.run(cmd, params = "", expected_outcodes = 0) ⇒ Object

Execute command with params and return output if exit status equal expected_outcodes



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/web_video/tools.rb', line 13

def self.run(cmd, params = "", expected_outcodes = 0)
  command = %Q[#{cmd} #{params}].gsub(/\s+/, " ")
  command = "#{command} 2>&1"
  
  WebVideo.logger.info(command)      
  
  sub = Subexec.run(command)
  
  unless Array.wrap(expected_outcodes).include?(sub.exitstatus)
    WebVideo.logger.info(sub.output)
    raise WebVideo::CommandLineError, "Error while running #{command}"
  end
  
  sub.output
end

.run_with_option(command_name, params, options = {}) ⇒ Object



6
7
8
# File 'lib/web_video/tools.rb', line 6

def self.run_with_option(command_name, params, options = {})
  run(command_name, apply_options(params, options))
end