-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
35d8248
commit 3229e09
Showing
6 changed files
with
178 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,6 +46,7 @@ module.exports = { | |
"model", | ||
"util", | ||
"todo", | ||
"version", | ||
], | ||
}, | ||
], | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package app | ||
|
||
// HadeVersion hade的版本 | ||
const HadeVersion = "1.0.3" |