Module: Scripto::RunCommands

Included in:
Scripto, Main
Defined in:
lib/scripto/run_commands.rb

Defined Under Namespace

Classes: CommandLine, Error

Instance Method Summary collapse

Instance Method Details

#run(command, args = nil) ⇒ Object



8
9
10
11
12
# File 'lib/scripto/run_commands.rb', line 8

def run(command, args = nil)
  cmd = CommandLine.new(command, args)
  vputs(cmd)
  cmd.run
end

#run_capture(command, args = nil) ⇒ Object



14
15
16
# File 'lib/scripto/run_commands.rb', line 14

def run_capture(command, args = nil)
  CommandLine.new(command, args).capture
end

#run_fails?(command, args = nil) ⇒ Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/scripto/run_commands.rb', line 32

def run_fails?(command, args = nil)
  !run_succeeds?(command, args)
end

#run_quietly(command, args = nil) ⇒ Object



18
19
20
21
# File 'lib/scripto/run_commands.rb', line 18

def run_quietly(command, args = nil)
  cmd = CommandLine.new(command, args)
  run("#{cmd} > /dev/null 2> /dev/null")
end

#run_succeeds?(command, args = nil) ⇒ Boolean

Returns:

  • (Boolean)


23
24
25
26
27
28
29
30
# File 'lib/scripto/run_commands.rb', line 23

def run_succeeds?(command, args = nil)
  begin
    run_quietly(command, args)
    true
  rescue Error
    false
  end
end

#shellescape(s) ⇒ Object



36
37
38
# File 'lib/scripto/run_commands.rb', line 36

def shellescape(s)
  Shellwords.escape(s)
end