diff options
author | Michael Stapelberg <stapelberg@debian.org> | 2014-06-19 09:22:53 +0200 |
---|---|---|
committer | Michael Stapelberg <stapelberg@debian.org> | 2014-06-19 09:22:53 +0200 |
commit | 8a39ee361feb9bf46d728ff1ba4f07ca1d9610b1 (patch) | |
tree | 4449f2036cccf162e8417cc5841a35815b3e7ac5 /src/cmd/gofmt/gofmt.go | |
parent | c8bf49ef8a92e2337b69c14b9b88396efe498600 (diff) | |
download | golang-8a39ee361feb9bf46d728ff1ba4f07ca1d9610b1.tar.gz |
Imported Upstream version 1.3upstream/1.3
Diffstat (limited to 'src/cmd/gofmt/gofmt.go')
-rw-r--r-- | src/cmd/gofmt/gofmt.go | 39 |
1 files changed, 11 insertions, 28 deletions
diff --git a/src/cmd/gofmt/gofmt.go b/src/cmd/gofmt/gofmt.go index 861ff9390..576cae522 100644 --- a/src/cmd/gofmt/gofmt.go +++ b/src/cmd/gofmt/gofmt.go @@ -31,21 +31,20 @@ var ( doDiff = flag.Bool("d", false, "display diffs instead of rewriting files") allErrors = flag.Bool("e", false, "report all errors (not just the first 10 on different lines)") - // layout control - comments = flag.Bool("comments", true, "print comments") - tabWidth = flag.Int("tabwidth", 8, "tab width") - tabIndent = flag.Bool("tabs", true, "indent with tabs") - // debugging cpuprofile = flag.String("cpuprofile", "", "write cpu profile to this file") ) +const ( + tabWidth = 8 + printerMode = printer.UseSpaces | printer.TabIndent +) + var ( - fileSet = token.NewFileSet() // per process FileSet - exitCode = 0 - rewrite func(*ast.File) *ast.File - parserMode parser.Mode - printerMode printer.Mode + fileSet = token.NewFileSet() // per process FileSet + exitCode = 0 + rewrite func(*ast.File) *ast.File + parserMode parser.Mode ) func report(err error) { @@ -60,22 +59,12 @@ func usage() { } func initParserMode() { - parserMode = parser.Mode(0) - if *comments { - parserMode |= parser.ParseComments - } + parserMode = parser.ParseComments if *allErrors { parserMode |= parser.AllErrors } } -func initPrinterMode() { - printerMode = printer.UseSpaces - if *tabIndent { - printerMode |= printer.TabIndent - } -} - func isGoFile(f os.FileInfo) bool { // ignore non-Go files name := f.Name() @@ -118,7 +107,7 @@ func processFile(filename string, in io.Reader, out io.Writer, stdin bool) error } var buf bytes.Buffer - err = (&printer.Config{Mode: printerMode, Tabwidth: *tabWidth}).Fprint(&buf, fileSet, file) + err = (&printer.Config{Mode: printerMode, Tabwidth: tabWidth}).Fprint(&buf, fileSet, file) if err != nil { return err } @@ -180,11 +169,6 @@ func main() { func gofmtMain() { flag.Usage = usage flag.Parse() - if *tabWidth < 0 { - fmt.Fprintf(os.Stderr, "negative tabwidth %d\n", *tabWidth) - exitCode = 2 - return - } if *cpuprofile != "" { f, err := os.Create(*cpuprofile) @@ -199,7 +183,6 @@ func gofmtMain() { } initParserMode() - initPrinterMode() initRewrite() if flag.NArg() == 0 { |