module MGMT

Constants

DEPSFILE
LOCKFILE
VENDOR
VERSION

Public Instance Methods

abort(msg) click to toggle source
# File bin/mgmt, line 33
def abort(msg)
  xputs "31", ">>> #{msg}"
  Kernel.exit(1)
end
exec(*c) click to toggle source
# File bin/mgmt, line 73
def exec(*c)
  ENV['GOPATH'] = [find_vendor, ENV['GOPATH']].compact.join(':')
  Kernel.exec(*c)
end
find_vendor() click to toggle source
# File bin/mgmt, line 78
def find_vendor
  Pathname.pwd.ascend do |dir|
    vendor = dir.join(VENDOR)
    return vendor if vendor.exist? && vendor.realpath.directory?
  end
end
lock(deps) click to toggle source
# File bin/mgmt, line 68
def lock(deps)
  deps.lock!
  MGMT.xputs "32", "=== #{LOCKFILE} written"
end
pull(deps) click to toggle source
# File bin/mgmt, line 46
def pull(deps)
  deps.each do |dep|
    MGMT.xputs "33",  "### #{dep.name}"
    if dep.pull!
      MGMT.xputs nil, "    now at ##{dep.version}"
    end
  end
end
read() click to toggle source
# File bin/mgmt, line 38
def read
  abort "#{DEPSFILE} not found" unless File.exist?(DEPSFILE)

  deps = Deps.parse(DEPSFILE, :tag)
  deps.merge! Deps.parse(LOCKFILE, :rev) if File.exist?(LOCKFILE)
  deps
end
sh(cmd) click to toggle source
# File bin/mgmt, line 23
def sh(cmd)
  system(cmd) || abort("Failed to execute command: #{cmd}")
end
shv(cmd) click to toggle source
# File bin/mgmt, line 27
def shv(cmd)
  value = `#{cmd}`
  abort "Failed to execute command: #{cmd}" unless $?.success?
  value.strip
end
update(deps, updates) click to toggle source
# File bin/mgmt, line 55
def update(deps, updates)
  versions = {}
  updates.each do |str|
    name, rev = str.split("#", 2)
    versions[name] = rev
  end
  deps.select do |dep|
    versions.include?(dep.name)
  end.each do |dep|
    dep.rev = versions[dep.name]
  end
end
xputs(code, msg) click to toggle source
# File bin/mgmt, line 15
def xputs(code, msg)
  code = nil if ENV['TERM'] != "xterm"
  print "\033[#{code}m" if code
  print msg
  print "\033[0m" if code
  print "\n"
end