add check command

This commit is contained in:
Star 2024-10-24 18:30:14 +08:00
parent 58b75b48d9
commit 847b1c8a62
3 changed files with 37 additions and 44 deletions

13
go.mod
View File

@ -1,24 +1,17 @@
module ag module ag
go 1.21 go 1.18
toolchain go1.22.5
require ( require (
github.com/ssgo/httpclient v1.7.7 github.com/ssgo/httpclient v1.7.8
github.com/ssgo/tool v0.4.27
github.com/ssgo/u v1.7.9 github.com/ssgo/u v1.7.9
) )
require ( require (
github.com/klauspost/compress v1.17.11 // indirect
github.com/nirhaas/gopacker v0.0.0-20190706195627-f33ba265006a // indirect
github.com/pkg/errors v0.8.1 // indirect
github.com/ssgo/config v1.7.7 // indirect github.com/ssgo/config v1.7.7 // indirect
github.com/ssgo/log v1.7.7 // indirect github.com/ssgo/log v1.7.7 // indirect
github.com/ssgo/standard v1.7.7 // indirect github.com/ssgo/standard v1.7.7 // indirect
github.com/ssgo/tool v0.4.27
github.com/ulikunitz/xz v0.5.6 // indirect
github.com/xi2/xz v0.0.0-20171230120015-48954b6210f8 // indirect
golang.org/x/net v0.30.0 // indirect golang.org/x/net v0.30.0 // indirect
golang.org/x/text v0.19.0 // indirect golang.org/x/text v0.19.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect

34
go.sum
View File

@ -1,34 +0,0 @@
github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
github.com/klauspost/compress v1.7.1 h1:VRD0WLa8rweLB7alA5WMSVkoAtrI8xou5RrNd4JUlR0=
github.com/klauspost/compress v1.7.1/go.mod h1:RyIbtBH6LamlWaDj8nUwkbUhJ87Yi3uG0guNDohfE1A=
github.com/klauspost/compress v1.17.11 h1:In6xLpyWOi1+C7tXUUWv2ot1QvBjxevKAaI6IXrJmUc=
github.com/klauspost/compress v1.17.11/go.mod h1:pMDklpSncoRMuLFrf1W9Ss9KT+0rH90U12bZKk7uwG0=
github.com/klauspost/cpuid v1.2.1/go.mod h1:Pj4uuM528wm8OyEC2QMXAi2YiTZ96dNQPGgoMS4s3ek=
github.com/nirhaas/gopacker v0.0.0-20190706195627-f33ba265006a h1:sJwCHMhWaEkZF9kM3pJ3jsucYtV1bMOm5lBCj25JH14=
github.com/nirhaas/gopacker v0.0.0-20190706195627-f33ba265006a/go.mod h1:Q5pT9vDBdamRfhFef15uVGELy2xdrxThCQkqlSf3qYg=
github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/ssgo/config v1.7.7 h1:gYYDuEEdesH41oNtvKHuwaua9quU655O8TRd3pBcuK8=
github.com/ssgo/config v1.7.7/go.mod h1:4mnR3YLGkmK+YnVT0NAbfUpvxqGyjyEElag+bH4zb0c=
github.com/ssgo/httpclient v1.7.7 h1:ex7pEwEpDaNtm334b04F0EQ62rPCNNxjOMi9tosXvGA=
github.com/ssgo/httpclient v1.7.7/go.mod h1:YA1MaQaThr8F9U1gnbUZhvUZY8ppAeI0A5GksPaVeYE=
github.com/ssgo/log v1.7.7 h1:EjgPGDTAEz+ApNyluLpof9QlftxBiqh1Jt3e3E0h/m4=
github.com/ssgo/log v1.7.7/go.mod h1:5E2Mkk+np9SCU84bX+lxBOG8QBD3XVkvFCbFi0RiKyk=
github.com/ssgo/standard v1.7.7 h1:5tnlcr9Nmftp7JI3jszYCEbW7VgS5HHsGueD+yWxbh0=
github.com/ssgo/standard v1.7.7/go.mod h1:LZcn56DzHu8OlDXrUPLI6h+RZbZRXhkmiKh6PSE8eDs=
github.com/ssgo/tool v0.4.27 h1:tB2VvEWt0jSazel2/G+/JmhsYesJWCeRLEdyV2r5QeM=
github.com/ssgo/tool v0.4.27/go.mod h1:qIQYzXya36WWVypWP5T/AgKwKBwZkEvMRfjACkAeUuw=
github.com/ssgo/u v1.7.9 h1:m1wcJWQg13+NbqpG+c2z3yWO+PC7qE3PIwKfXhQqdPg=
github.com/ssgo/u v1.7.9/go.mod h1:dUG/PBG5k9fSM7SOp8RZLsK0KytNxhtenpoLgjhfxpY=
github.com/ulikunitz/xz v0.5.6 h1:jGHAfXawEGZQ3blwU5wnWKQJvAraT7Ftq9EXjnXYgt8=
github.com/ulikunitz/xz v0.5.6/go.mod h1:2bypXElzHzzJZwzH67Y6wb67pO62Rzfn7BSiF4ABRW8=
github.com/xi2/xz v0.0.0-20171230120015-48954b6210f8 h1:nIPpBwaJSVYIxUFsDv3M8ofmx9yWTog9BfvIu0q41lo=
github.com/xi2/xz v0.0.0-20171230120015-48954b6210f8/go.mod h1:HUYIGzjTL3rfEspMxjDjgmT5uz5wzYJKVo23qUhYTos=
golang.org/x/net v0.30.0 h1:AcW1SDZMkb8IpzCdQUaIq2sP4sZ4zw+55h6ynffypl4=
golang.org/x/net v0.30.0/go.mod h1:2wGyMJ5iFasEhkwi13ChkO/t1ECNC4X4eBKkVFyYFlU=
golang.org/x/text v0.19.0 h1:kTxAhCbGbxhK0IwgSKiMO5awPoDQ0RpfiVYBfK860YM=
golang.org/x/text v0.19.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

34
main.go
View File

@ -70,6 +70,7 @@ var commands = []Command{
{"test", "t", "[args...]", "test project", testProject}, {"test", "t", "[args...]", "test project", testProject},
{"buildtest", "tt", "[args...]", "build and test project", buildTestProject}, {"buildtest", "tt", "[args...]", "build and test project", buildTestProject},
{"tidy", "td", "", "tidy project, run go mod tidy", tidyProject}, {"tidy", "td", "", "tidy project, run go mod tidy", tidyProject},
{"check", "ck", "", "check go modules version", checkProject},
{"export", "e", "", "export typescript code for dev", exportForDev}, {"export", "e", "", "export typescript code for dev", exportForDev},
{"tags", "", "", "show git tags", showGitTags}, {"tags", "", "", "show git tags", showGitTags},
{"add tag", "t+", "[version]", "add git tag and push, if no new tag specified will use last tag +1", addGitTag}, {"add tag", "t+", "[version]", "add git tag and push, if no new tag specified will use last tag +1", addGitTag},
@ -932,6 +933,39 @@ func tidyProject(args []string) bool {
return true return true
} }
func checkProject(args []string) bool {
if lines, err := u.RunCommand(goPath, "list", "-m", "-u", "all"); err == nil {
moduleList := map[string]string{}
indirectModuleList := map[string]string{}
for _, line := range u.ReadFileLinesN("go.mod") {
if strings.Contains(line, " v") {
a := strings.Split(strings.TrimSpace(line), " ")
if strings.Contains(line, "// indirect") {
indirectModuleList[a[0]] = a[1]
} else {
moduleList[a[0]] = a[1]
}
}
}
for _, line := range lines {
a := strings.Split(line, " ")
if len(a) > 2 {
if oldVer, ok := moduleList[a[0]]; ok {
fmt.Println(u.BCyan(a[0]), u.BMagenta(oldVer), u.BGreen(a[2]))
} else if _, ok := indirectModuleList[a[0]]; ok {
fmt.Println(u.Cyan(a[0]), u.BMagenta(indirectModuleList[a[0]]), u.BGreen(a[2]))
} else {
fmt.Println(a[0], u.BMagenta(a[1]), u.BGreen(a[2]))
}
}
}
} else {
fmt.Println(strings.Join(lines, "\n"))
fmt.Println(u.Red(err.Error()))
}
return true
}
func runCommand(name string, args ...string) error { func runCommand(name string, args ...string) error {
return runCommandWithEnv(name, nil, args...) return runCommandWithEnv(name, nil, args...)
} }