gomod/gomod/main.go
2023-06-11 18:46:51 +08:00

57 lines
1008 B
Go

package main
import (
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"gitter.top/coco/lormatter"
"gitter.top/apps/gomod"
)
var mod *cobra.Command
func init() {
formatter := &lormatter.Formatter{}
logrus.SetFormatter(formatter)
logrus.SetReportCaller(true)
mod = &cobra.Command{
Use: "gomod",
Short: "go mod manager",
}
mod.AddCommand(all())
mod.AddCommand(single())
}
func all() *cobra.Command {
return &cobra.Command{
Use: "all",
Short: "upgrade all go mod",
Run: func(cmd *cobra.Command, args []string) {
gomod.AllModUpgrade()
},
}
}
func single() *cobra.Command {
return &cobra.Command{
Use: "one",
Short: "upgrade go mod from url",
Run: func(cmd *cobra.Command, args []string) {
if len(args) == 0 {
logrus.Error("url empty, skip upgrade")
return
}
for _, url := range args {
gomod.SingleModUpgrade(url)
}
},
}
}
func main() {
if err := mod.Execute(); err != nil {
logrus.Errorf("execute command failed: %v", err)
}
}