mirror of
https://github.com/golang/go
synced 2024-11-18 10:04:43 -07:00
goimports: create a var to permit custom implementations of flag parsing and
startup work. Change-Id: I9e60ec785313295bce614b5735238943af607223 Reviewed-on: https://go-review.googlesource.com/8204 Reviewed-by: David Crawshaw <crawshaw@golang.org>
This commit is contained in:
parent
e77366c32d
commit
1e216dc2e3
@ -135,9 +135,16 @@ func main() {
|
||||
os.Exit(exitCode)
|
||||
}
|
||||
|
||||
// parseFlags parses command line flags and returns the paths to process.
|
||||
// It's a var so that custom implementations can replace it in other files.
|
||||
var parseFlags = func() []string {
|
||||
flag.Parse()
|
||||
return flag.Args()
|
||||
}
|
||||
|
||||
func gofmtMain() {
|
||||
flag.Usage = usage
|
||||
flag.Parse()
|
||||
paths := parseFlags()
|
||||
|
||||
if options.TabWidth < 0 {
|
||||
fmt.Fprintf(os.Stderr, "negative tabwidth %d\n", options.TabWidth)
|
||||
@ -145,15 +152,14 @@ func gofmtMain() {
|
||||
return
|
||||
}
|
||||
|
||||
if flag.NArg() == 0 {
|
||||
if len(paths) == 0 {
|
||||
if err := processFile("<standard input>", os.Stdin, os.Stdout, true); err != nil {
|
||||
report(err)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
for i := 0; i < flag.NArg(); i++ {
|
||||
path := flag.Arg(i)
|
||||
for _, path := range paths {
|
||||
switch dir, err := os.Stat(path); {
|
||||
case err != nil:
|
||||
report(err)
|
||||
|
Loading…
Reference in New Issue
Block a user