Go fmt on a whole source tree

前端 未结 6 877
借酒劲吻你
借酒劲吻你 2021-01-30 03:36

I have a project currently organized something like this:

~/code/go
         /bin
         /pkg
         /src
             /proj/main.go
                  /some_packa         


        
6条回答
  •  执笔经年
    2021-01-30 04:22

    find proj -type f -iregex '.*\.go' -exec go fmt '{}' +
    

    Explanation

    • find proj: find everything in this directory...
      • -type f: ...that is a file
      • -iregex '.*\.go': ...and case-insensitively matches the regular expression .*\.go
    • ...and execute go fmt followed by as many matched files as the operating system can handle passing to an executable in one go.

提交回复
热议问题