Skip to content

Commit

Permalink
walk path only to formating
Browse files Browse the repository at this point in the history
  • Loading branch information
go-wyvern committed Oct 9, 2021
1 parent 4721480 commit 4404380
Showing 1 changed file with 12 additions and 16 deletions.
28 changes: 12 additions & 16 deletions cmd/gopfmt/gopfmt.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"io/ioutil"
"os"
"path/filepath"
"strings"
)

var (
Expand Down Expand Up @@ -105,6 +106,7 @@ func walk(path string, d fs.DirEntry, err error) error {
return filepath.SkipDir
}
} else {
// Directories are walked, ignoring non-Gop files.
ext := filepath.Ext(path)
if _, ok := extGops[ext]; ok {
procCnt++
Expand All @@ -130,22 +132,16 @@ func main() {
return
}

for _, arg := range args {
switch info, err := os.Stat(arg); {
case err != nil:
report(err)
case !info.IsDir():
// Non-directory arguments are always formatted.
arg := arg
if err := processFile(arg, nil, nil); err != nil {
report(err)
}
default:
// Directories are walked, ignoring non-Gop files.
err := filepath.WalkDir(arg, walk)
if err != nil {
report(err)
}
for _, path := range args {
walkSubDir = strings.HasSuffix(path, "/...")
if walkSubDir {
path = path[:len(path)-4]
}
procCnt = 0
rootDir = path
filepath.WalkDir(path, walk)
if procCnt == 0 {
fmt.Println("no Go+ files in", path)
}
}
}
Expand Down

0 comments on commit 4404380

Please sign in to comment.