first commit
This commit is contained in:
commit
08d0662fe6
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
.idea
|
||||||
|
go.sum
|
5
coco_config.go
Normal file
5
coco_config.go
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
type Config struct {
|
||||||
|
Version string `yaml:"version"`
|
||||||
|
}
|
54
coco_update.go
Normal file
54
coco_update.go
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"github.com/sirupsen/logrus"
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
gitea_api "gitter.top/coco/components/gitea-api"
|
||||||
|
"gitter.top/coco/components/runtime"
|
||||||
|
"gitter.top/coco/components/yaml"
|
||||||
|
)
|
||||||
|
|
||||||
|
func cocoUpdate() *cobra.Command {
|
||||||
|
var config Config
|
||||||
|
var configPath string
|
||||||
|
return &cobra.Command{
|
||||||
|
Use: "update",
|
||||||
|
Short: "coco tool update",
|
||||||
|
PreRun: func(cmd *cobra.Command, args []string) {
|
||||||
|
configPath = runtime.ReplaceEachSlash(fmt.Sprintf("%s/.coco.yaml", runtime.GetHomeDir()))
|
||||||
|
_ = yaml.Read(configPath, &config)
|
||||||
|
},
|
||||||
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
|
client, err := gitea_api.NewClient("https://gitter.top")
|
||||||
|
if err != nil {
|
||||||
|
logrus.Errorf("new gitea api failed: %v", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
commitID, err := client.GetLatestCommitID("coco", "bootstrap")
|
||||||
|
if err != nil {
|
||||||
|
logrus.Errorf("get coco bootstrap info failed: %v", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if commitID == config.Version {
|
||||||
|
logrus.Infof("version is latest!")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// exec update
|
||||||
|
repo := fmt.Sprintf("gitter.top/coco/bootstrap@%s", commitID)
|
||||||
|
if output, err := runtime.Exec("go", "build", "-o", "coco", repo); err != nil {
|
||||||
|
logrus.Errorf("update coco failed: %v", err)
|
||||||
|
return
|
||||||
|
} else {
|
||||||
|
logrus.Infof("%s", output)
|
||||||
|
}
|
||||||
|
|
||||||
|
config.Version = commitID
|
||||||
|
if err := yaml.Write(configPath, &config); err != nil {
|
||||||
|
logrus.Errorf("write config failed: %v", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
18
go.mod
Normal file
18
go.mod
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
module gitter.top/xuthus5/coco
|
||||||
|
|
||||||
|
go 1.18
|
||||||
|
|
||||||
|
require (
|
||||||
|
github.com/sirupsen/logrus v1.9.0
|
||||||
|
github.com/spf13/cobra v1.6.1
|
||||||
|
gitter.top/coco/components v0.0.0-20230101151943-8e94d6d01339
|
||||||
|
)
|
||||||
|
|
||||||
|
require (
|
||||||
|
code.gitea.io/sdk/gitea v0.15.1 // indirect
|
||||||
|
github.com/hashicorp/go-version v1.2.1 // indirect
|
||||||
|
github.com/inconshreveable/mousetrap v1.0.1 // indirect
|
||||||
|
github.com/spf13/pflag v1.0.5 // indirect
|
||||||
|
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8 // indirect
|
||||||
|
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||||
|
)
|
23
main.go
Normal file
23
main.go
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/sirupsen/logrus"
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
rootCmd = &cobra.Command{
|
||||||
|
Use: "coco",
|
||||||
|
Short: "golang project generator",
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
rootCmd.AddCommand(cocoUpdate())
|
||||||
|
}
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
if err := rootCmd.Execute(); err != nil {
|
||||||
|
logrus.Fatalln(err)
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user