如何在除了Godeps和.git之外的所有文件夹上运行goimports?

huangapple go评论74阅读模式
英文:

How to run goimports on all folders except Godeps and .git?

问题

你可以在 Makefile 中使用以下命令来运行 goimports,并排除 Godeps 和 .git 文件夹:

run_goimports:
    find . -type d \( -name Godeps -o -name .git \) -prune -o -type f -name '*.go' -exec goimports -w {} +

这个命令使用 find 命令来查找除了 Godeps 和 .git 文件夹之外的所有文件夹中的所有 .go 文件,并将它们传递给 goimports 命令进行格式化。

英文:

How can I run goimports on all folders expect Godeps and .git from a Makefile?

答案1

得分: 9

使用find命令列出所有的go文件,并对其运行goimports -w命令:

find . -name \*.go -not -path <要忽略的文件夹> -not -path <另一个要忽略的文件夹> -exec goimports -w {} \;
英文:

Use find to list all your go files and run a command goimports -w over it:

find . -name \*.go -not -path &lt;FOLDER TO IGNORE&gt; -not -path &lt;ANOTHER FOLDER TO IGNORE&gt; -exec goimports -w {} \;

huangapple
  • 本文由 发表于 2016年2月12日 10:18:43
  • 转载请务必保留本文链接:https://go.coder-hub.com/35353717.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定