/
go.go
53 lines (44 loc) · 1.16 KB
/
go.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package grimoire
import (
"fmt"
"github.com/fatih/color"
"github.com/magefile/mage/mg"
"github.com/magefile/mage/sh"
)
// Go is a mage namespace which will manage golang actions
type Go mg.Namespace
// Tidy add/remove depenedencies.
func (Go) Tidy() error {
fmt.Println("## Cleaning go modules")
return sh.RunV("go", "mod", "tidy", "-v")
}
// Deps install dependency tools.
func (Go) Deps() error {
color.Cyan("## Vendoring dependencies")
return sh.RunV("go", "mod", "vendor")
}
// License check that project dont used blacklisted licenses
func (Go) License() error {
color.Cyan("## Check license")
return sh.RunV("wwhrd", "check")
}
// Format runs gofmt on everything
func (Go) Format() error {
color.Cyan("## Format everything")
args := []string{"-s", "-w"}
args = append(args, goFiles...)
return sh.RunV("gofumpt", args...)
}
// Import runs goimports on everything
func (Go) Import() error {
color.Cyan("## Process imports")
args := []string{"-w"}
args = append(args, goSrcFiles...)
return sh.RunV("goreturns", args...)
}
// Lint run linter.
func (Go) Lint() error {
mg.Deps(Go.Format)
color.Cyan("## Lint go code")
return sh.RunV("golangci-lint", "run")
}