github.com/razvanm/vanadium-go-1.3@v0.0.0-20160721203343-4a65068e5915/src/cmd/go/fmt.go (about) 1 // Copyright 2011 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package main 6 7 func init() { 8 addBuildFlagsNX(cmdFmt) 9 } 10 11 var cmdFmt = &Command{ 12 Run: runFmt, 13 UsageLine: "fmt [-n] [-x] [packages]", 14 Short: "run gofmt on package sources", 15 Long: ` 16 Fmt runs the command 'gofmt -l -w' on the packages named 17 by the import paths. It prints the names of the files that are modified. 18 19 For more about gofmt, see 'godoc gofmt'. 20 For more about specifying packages, see 'go help packages'. 21 22 The -n flag prints commands that would be executed. 23 The -x flag prints commands as they are executed. 24 25 To run gofmt with specific options, run gofmt itself. 26 27 See also: go fix, go vet. 28 `, 29 } 30 31 func runFmt(cmd *Command, args []string) { 32 for _, pkg := range packages(args) { 33 // Use pkg.gofiles instead of pkg.Dir so that 34 // the command only applies to this package, 35 // not to packages in subdirectories. 36 run(stringList("gofmt", "-l", "-w", relPaths(pkg.allgofiles))) 37 } 38 }