Skip to content

Commit

Permalink
add version command
Browse files Browse the repository at this point in the history
  • Loading branch information
jianfengye committed Dec 11, 2022
1 parent 35d8248 commit 3229e09
Show file tree
Hide file tree
Showing 6 changed files with 178 additions and 1 deletion.
1 change: 1 addition & 0 deletions docs/.vuepress/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ module.exports = {
"model",
"util",
"todo",
"version",
],
},
],
Expand Down
54 changes: 54 additions & 0 deletions docs/guide/version.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# 版本

hade 提供了查询当前版本和获取最新版本日志的命令

## 查询当前版本

使用命令 `hade version`

```
➜ hade git:(main) ✗ ./hade version
hade version: 1.0.3
```

## 获取最新的版本

使用命令 `hade version list`

```
➜ hade git:(main) ✗ ./hade version list
===============前置条件检测===============
hade源码从github.com中下载,正在检测到github.com的连接
github.Rate{Limit:60, Remaining:29, Reset:github.Timestamp{2022-12-11 17:43:48 +0800 CST}}
hade源码从github.com中下载,github.com的连接正常
===============前置条件检测结束===============
最新的6个版本
-v1.0.2
发布时间:2022-12-11 08:57:37
修改说明:
创建1.0.2
-v1.0.1
发布时间:2021-12-28 08:22:58
修改说明:
1 增加了一个计划版本
-v1.0.0
发布时间:2021-11-21 18:02:00
修改说明:
create release
-v0.0.3
发布时间:2021-10-08 23:13:52
修改说明:
完善new命令
-v0.0.2
发布时间:2021-10-06 09:19:44
修改说明:
1 增加了环境变量设置
2 增加了前后端一体化
-v0.0.1
发布时间:2021-10-06 09:20:28
修改说明:
第一版本
更多历史版本请参考 https://github.com/gohade/hade/releases
```
2 changes: 2 additions & 0 deletions framework/command/kernel.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ func AddKernelCommands(root *cobra.Command) {
root.AddCommand(initDeployCommand())
// model
root.AddCommand(model.InitModelCommand())
// version
root.AddCommand(initVersionCommand())
}

// InitCronCommands 初始化Cron相关的命令
Expand Down
116 changes: 116 additions & 0 deletions framework/command/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
package command

import (
"context"
"fmt"
"github.com/AlecAivazis/survey/v2"
"github.com/google/go-github/v39/github"
"net/http"
"net/url"
"strings"

"github.com/gohade/hade/framework/cobra"
"github.com/gohade/hade/framework/contract"
)

// initEnvCommand 获取env相关的命令
func initVersionCommand() *cobra.Command {
versionCommand.AddCommand(versionListCommand)
return versionCommand
}

var versionCommand = &cobra.Command{
Use: "version",
Short: "当前hade的版本",
Run: func(c *cobra.Command, args []string) {
container := c.GetContainer()
appService := container.MustMake(contract.AppKey).(contract.App)
fmt.Println("hade version:", appService.Version())
},
}

var versionListCommand = &cobra.Command{
Use: "list",
Short: "获取最新的hade的版本",
RunE: func(c *cobra.Command, args []string) error {
// 检测到github的连接
fmt.Println("===============前置条件检测===============")
fmt.Println("hade源码从github.com中下载,正在检测到github.com的连接")
var client *github.Client
client = github.NewClient(nil)
perPage := 10
opts := &github.ListOptions{Page: 1, PerPage: perPage}
releases, rsp, err := client.Repositories.ListReleases(context.Background(), "gohade", "hade", opts)
fmt.Println(rsp.Rate.String())
if err != nil {
if _, ok := err.(*github.RateLimitError); ok {
fmt.Println("错误提示:" + err.Error())
fmt.Println("说明你的出口ip遇到github的调用限制,可以使用github.com帐号登录方式来增加调用次数")
githubUserName := ""
prompt := &survey.Input{
Message: "请输入github帐号用户名:",
}
if err := survey.AskOne(prompt, &githubUserName); err != nil {
fmt.Println("任务终止:" + err.Error())
return nil
}
githubPassword := ""
promptPwd := &survey.Password{
Message: "请输入github帐号密码:",
}
if err := survey.AskOne(promptPwd, &githubPassword); err != nil {
fmt.Println("任务终止:" + err.Error())
return nil
}

httpClient := &http.Client{
Transport: &http.Transport{
Proxy: func(req *http.Request) (*url.URL, error) {
req.SetBasicAuth(githubUserName, githubPassword)
return nil, nil
},
},
}
client = github.NewClient(httpClient)
releases, rsp, err = client.Repositories.ListReleases(context.Background(), "gohade", "hade", opts)
if err != nil {
fmt.Println("错误提示:" + err.Error())
fmt.Println("用户名密码错误,请重新开始")
return nil
}
if len(releases) == 0 {
fmt.Println("用户名密码错误,请重新开始")
return nil
}
fmt.Println(rsp.Rate.String())
} else {
fmt.Println("github.com的连接异常:" + err.Error())
return nil
}
}
fmt.Println("hade源码从github.com中下载,github.com的连接正常")
// 这里下面的client都是可用的了
if rsp.LastPage != 0 {
opts = &github.ListOptions{Page: rsp.LastPage, PerPage: perPage}
releases, rsp, err = client.Repositories.ListReleases(context.Background(), "gohade", "hade", opts)
if err != nil {
fmt.Println("任务终止:" + err.Error())
return nil
}
fmt.Println(rsp.Rate.String())
}
fmt.Println("===============前置条件检测结束===============")
fmt.Printf("\n")
fmt.Printf("最新的%v个版本\n", len(releases))
for _, releaseTmp := range releases {
fmt.Println("-" + releaseTmp.GetTagName())
fmt.Println(" 发布时间:" + releaseTmp.GetPublishedAt().Format("2006-01-02 15:04:05"))
fmt.Println(" 修改说明:")
fmt.Println(" " + strings.ReplaceAll(releaseTmp.GetBody(), "\n", "\n "))
}
fmt.Printf("\n")

fmt.Printf("更多历史版本请参考 https://github.com/gohade/hade/releases\n")
return nil
},
}
2 changes: 1 addition & 1 deletion framework/provider/app/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func (app HadeApp) AppID() string {

// Version 实现版本
func (app HadeApp) Version() string {
return "0.0.3"
return HadeVersion
}

// BaseFolder 表示基础目录,可以代表开发场景的目录,也可以代表运行时候的目录
Expand Down
4 changes: 4 additions & 0 deletions framework/provider/app/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package app

// HadeVersion hade的版本
const HadeVersion = "1.0.3"

0 comments on commit 3229e09

Please sign in to comment.