File: run.rb

package info (click to toggle)
ruby-spamcheck 1.0.0%2Bgit20220819.662e6bf-2
  • links: PTS, VCS
  • area: contrib
  • in suites: bookworm
  • size: 620 kB
  • sloc: python: 828; ruby: 422; makefile: 40
file content (36 lines) | stat: -rw-r--r-- 749 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
def run!(cmd, chdir='.')
  SpamCheckSupport.print_cmd(cmd)
  unless system(*cmd, chdir: chdir)
    SpamCheckSupport.fail_cmd!(cmd)
  end
end

def run2!(cmd, chdir: '.', out: 1)
  SpamCheckSupport.print_cmd(cmd)
  unless system(*cmd, chdir: chdir, out: out)
    SpamCheckSupport.fail_cmd!(cmd)
  end
end

def capture!(cmd, chdir='.')
  SpamCheckSupport.print_cmd(cmd)
  output = IO.popen(cmd, chdir: chdir) { |io| io.read }
  SpamCheckSupport.fail_cmd!(cmd) unless $?.success?
  output
end

module SpamCheckSupport
  class << self
    def print_cmd(cmd)
      puts '-> ' + printable_cmd(cmd)
    end

    def fail_cmd!(cmd)
      abort "command failed: #{printable_cmd(cmd)}"
    end

    def printable_cmd(cmd)
      cmd.join(' ')
    end
  end
end