class Object
Constants
- HOMEBREW_CELLAR
Public Instance Methods
cmd_common()
click to toggle source
# File bin/brew-go, line 52 def cmd_common puts <<HEREDOC Here are a few commonly used tools. The names can be used as shortcuts: $ brew go get guru HEREDOC print_formatted_list(@commons) end
cmd_get(packages)
click to toggle source
# File bin/brew-go, line 61 def cmd_get(packages) threads = [] packages = resolve_common_packages packages packages.each do |url| threads << Thread.new do name = File.basename url cellarpath = "#{HOMEBREW_CELLAR}/brew-go-#{name}" gopath = "#{cellarpath}/#{url.tr '/', '#'}" ENV['GOPATH'] = gopath ENV.delete 'GOBIN' system "go get #{url}" unless $?.success? puts "[\x1b[31;1m✗\x1b[0m] #{url}" FileUtils.remove_dir cellarpath, true Thread.exit end puts "[\x1b[32;1m✓\x1b[0m] \x1b[1m#{name}\x1b[0m (#{url})" FileUtils.remove_dir "#{gopath}/pkg", true FileUtils.remove_dir "#{gopath}/src", true system "brew unlink brew-go-#{name}", out: File::NULL system "brew link brew-go-#{name}", out: File::NULL end end threads.each(&:join) end
cmd_list(name)
click to toggle source
# File bin/brew-go, line 93 def cmd_list(name) if name.nil? installed = {} Dir["#{HOMEBREW_CELLAR}/brew-go-*/*"].each do |path| name = File.basename(Pathname(path).parent.to_s).sub('brew-go-', '') url = get_url_from_cellar_path(path) installed[name] = url end print_formatted_list(installed) return end name = "brew-go-#{name}" unless name.start_with?('brew-go') path = "#{HOMEBREW_CELLAR}/#{name}" if Dir.exist? path puts(Dir["#{path}/**/*"].select { |f| File.file? f }) else puts "No such keg: #{path}" exit 1 end end
cmd_rm(names)
click to toggle source
# File bin/brew-go, line 115 def cmd_rm(names) names.each do |name| name = "brew-go-#{name}" unless name.start_with?('brew-go-') system "brew uninstall #{name}" end end
cmd_update(names)
click to toggle source
# File bin/brew-go, line 122 def cmd_update(names) names = names.map do |name| name.start_with?('brew-go-') ? name : "brew-go-#{name}" end urls = if names.empty? Dir["#{HOMEBREW_CELLAR}/brew-go-*/*"].map do |path| get_url_from_cellar_path path end else names.map do |name| get_url_from_cellar_path Dir["#{HOMEBREW_CELLAR}/#{name}/*"].first end end cmd_get urls end
get_url_from_cellar_path(path)
click to toggle source
# File bin/brew-go, line 138 def get_url_from_cellar_path(path) File.basename(path).tr '#', '/' end
helpme()
click to toggle source
# File bin/brew-go, line 29 def helpme puts <<HEREDOC Manage Go packages via Homebrew. Usage: $ brew go get <url to package> ... $ brew go rm <name> ... $ brew go list [name] $ brew go update [name] ... $ brew go common Examples: $ brew go get golang.org/x/tools/cmd/guru $ brew go get guru $ brew go list $ brew go list brew-go-guru $ brew go list guru $ brew go update $ brew go update guru HEREDOC exit 1 end
print_formatted_list(packages)
click to toggle source
# File bin/brew-go, line 146 def print_formatted_list(packages) maxlen = packages.keys.map(&:length).max packages.sort.each do |name, url| puts "\x1b[1m#{name.ljust(maxlen)}\x1b[0m (#{url})" end end
resolve_common_packages(packages)
click to toggle source
# File bin/brew-go, line 142 def resolve_common_packages(packages) packages.map { |p| @commons[p] || p } end