Top Level Namespace

Defined Under Namespace

Classes: Array, Hash, String, Symbol

Instance Method Summary collapse

Instance Method Details

#expand_cmd(*arguments) ⇒ Object



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

def expand_cmd(*arguments)
  command = arguments.shift.to_s
  cmd = command + ' ' + arguments.map{|a| a.to_cmd_opt}.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
# File 'lib/ruby-unix-now.rb', line 6

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