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)
|
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() {
|
func gofmtMain() {
|
||||||
flag.Usage = usage
|
flag.Usage = usage
|
||||||
flag.Parse()
|
paths := parseFlags()
|
||||||
|
|
||||||
if options.TabWidth < 0 {
|
if options.TabWidth < 0 {
|
||||||
fmt.Fprintf(os.Stderr, "negative tabwidth %d\n", options.TabWidth)
|
fmt.Fprintf(os.Stderr, "negative tabwidth %d\n", options.TabWidth)
|
||||||
|
|
@ -145,15 +152,14 @@ func gofmtMain() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if flag.NArg() == 0 {
|
if len(paths) == 0 {
|
||||||
if err := processFile("<standard input>", os.Stdin, os.Stdout, true); err != nil {
|
if err := processFile("<standard input>", os.Stdin, os.Stdout, true); err != nil {
|
||||||
report(err)
|
report(err)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
for i := 0; i < flag.NArg(); i++ {
|
for _, path := range paths {
|
||||||
path := flag.Arg(i)
|
|
||||||
switch dir, err := os.Stat(path); {
|
switch dir, err := os.Stat(path); {
|
||||||
case err != nil:
|
case err != nil:
|
||||||
report(err)
|
report(err)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue