Top Level Namespace

Defined Under Namespace

Classes: Array, Hash, Symbol

Instance Method Summary collapse

Instance Method Details

#expand_cmd(*arguments) ⇒ Object



22
23
24
25
# File 'lib/ruby-unix-now.rb', line 22

def expand_cmd(*arguments)
  command = arguments.shift.to_s
  cmd = command + ' ' + arguments.map{|a| a.respond_to?(:to_cmd_opt) ? a.to_cmd_opt : a.to_s}.join(' ')
end

#log(msg, level = 0) ⇒ Object



2
3
4
# File 'lib/ruby-unix-now.rb', line 2

def log(msg, level = 0)
  puts (' ' * (level * 2)) + '# ' + msg
end

#run(*arguments) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/ruby-unix-now.rb', line 6

def run(*arguments)
  options = (arguments.last.is_a?(Hash) && arguments.last) || {}
  sync = options.delete(:sync)
  cmd = expand_cmd(*arguments)
  log(cmd)
  result = if sync
    `#{cmd}`
  else
    system(cmd)
  end
  unless $?.success?
    exit -1
  end
  result
end