summaryrefslogtreecommitdiff
path: root/support/go-format
blob: 59af23c1e485493d05ada1e09ddcd70279494656 (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']
  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')