Module: Vx::Aptly::Mixin::Capture

Included in:
Package, Package, Repo, Repo, RepoPublish, RepoPublish
Defined in:
lib/vx/aptly/mixin/capture.rb

Instance Method Summary collapse

Instance Method Details

#capture(cmd) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/vx/aptly/mixin/capture.rb', line 6

def capture(cmd)
  Aptly.logger.write "[aptly] #{cmd}\n" unless silent?
  rs = `#{cmd} 2>&1`
  st = $?.exitstatus
  if st != 0
    txt = "The command '#{cmd}' exit with status #{st}\n\n"

    rs.lines do |line|
      Aptly.logger.write "[aptly:ERROR] #{line}" unless silent?
      txt << line
    end

    txt = txt.strip
    raise AptlyCommandError, txt
  end
  if block_given?
    yield rs
  else
    rs
  end
end