Add fmt check command

This commit is contained in:
kolaente 2020-09-01 16:59:23 +02:00
parent db03a45165
commit 6ec1ce9730
Signed by: konrad
GPG Key ID: F40E70337AB24C9B
1 changed files with 15 additions and 1 deletions

View File

@ -216,8 +216,22 @@ func Fmt() {
}
// Checks if the code is properly formatted with go fmt
func FmtCheck() {
func FmtCheck() error {
args := append([]string{"-s", "-d"}, GoFiles...)
c := exec.Command("gofmt", args...)
out, err := c.Output()
if err != nil {
return err
}
if len(out) > 0 {
fmt.Println("Code is not properly gofmt'ed.")
fmt.Println("Please run 'mage fmt' and commit the result:")
fmt.Print(string(out))
os.Exit(1)
}
return nil
}
func Lint() {