summaryrefslogtreecommitdiff
path: root/support/go-format
blob: b5f47b75c37a9226420c54d30af41ae4b1afbfba (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#!/usr/bin/env ruby

def main(check)
  go_files = Dir['go/**/*.go'].reject { |p| p.start_with?('go/vendor/') }
  cmd = %w[gofmt -s -l]
  cmd << '-w' unless check
  cmd += go_files
  output = IO.popen(cmd, 'r', &:read)
  $stdout.write(output)
  abort 'gofmt failed' unless $?.success?
  if check && output.lines.any? { |l| l != "\n" }
    abort "\nPlease run #{$0} to fix formatting"
  end
end

main(ARGV.first == 'check')