diff options
Diffstat (limited to 'support/go-format')
-rwxr-xr-x | support/go-format | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/support/go-format b/support/go-format new file mode 100755 index 0000000..d74fc46 --- /dev/null +++ b/support/go-format @@ -0,0 +1,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') { |io| io.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') |