diff options
Diffstat (limited to 'libgo/go/cmd/go/fmt.go')
-rw-r--r-- | libgo/go/cmd/go/fmt.go | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/libgo/go/cmd/go/fmt.go b/libgo/go/cmd/go/fmt.go new file mode 100644 index 0000000000..65dc3ca599 --- /dev/null +++ b/libgo/go/cmd/go/fmt.go @@ -0,0 +1,38 @@ +// Copyright 2011 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +func init() { + addBuildFlagsNX(cmdFmt) +} + +var cmdFmt = &Command{ + Run: runFmt, + UsageLine: "fmt [-n] [-x] [packages]", + Short: "run gofmt on package sources", + Long: ` +Fmt runs the command 'gofmt -l -w' on the packages named +by the import paths. It prints the names of the files that are modified. + +For more about gofmt, see 'godoc gofmt'. +For more about specifying packages, see 'go help packages'. + +The -n flag prints commands that would be executed. +The -x flag prints commands as they are executed. + +To run gofmt with specific options, run gofmt itself. + +See also: go fix, go vet. + `, +} + +func runFmt(cmd *Command, args []string) { + for _, pkg := range packages(args) { + // Use pkg.gofiles instead of pkg.Dir so that + // the command only applies to this package, + // not to packages in subdirectories. + run(stringList("gofmt", "-l", "-w", relPaths(pkg.allgofiles))) + } +} |