Skip to content

Commit

Permalink
Merge pull request #11 from ysicing/b2
Browse files Browse the repository at this point in the history
feat(release 2.0.3): 支持cloud & code subcmd
  • Loading branch information
ysicing authored Oct 13, 2021
2 parents 456a5ef + a9e5635 commit 31d8d69
Show file tree
Hide file tree
Showing 44 changed files with 1,519 additions and 2,050 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
## Ergo CHANGELOG

- v2.0.3
- 新增code命令,支持初始化crds/go项目
- plugin增强, 参考helm repo

- v2.0.2
- repo新增redis,etcd,mongodb,consul,minio,postgresql,rabbitmq

Expand Down
35 changes: 28 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ ergo upgrade

## 命令支持

- [x] code 初始化项目
- [x] completion
- [x] debian
- [x] `init` 初始化debian
Expand All @@ -40,12 +41,19 @@ ergo upgrade
- [x] `nc` nc
- [x] `exec` 执行命令
- [x] plugin
- [x] `install` 安装插件
- [x] `list` 列出ergo插件
- [x] `ls-remote` 列出远程插件
- [x] `repo` 插件仓库管理, 类似helm仓库
- [x] `add` 添加插件仓库
- [x] `list` 列出插件仓库列表
- [x] `del` 移除插件仓库
- [x] `update` 更新插件索引
- [x] repo
- [x] `list` 列出支持的软件包
- [x] `install` 安装软件包
- [x] containerd
- [x] mysql,redis,etcd,mongodb,consul,minio,postgresql,rabbitmq
- [x] `containerd`
- [x] `mysql`
- [x] `dump` dump安装脚本
- [x] upgrade
- [x] version
Expand All @@ -70,17 +78,30 @@ echo $@
# 使用
ergo doge haha
haha

# 插件仓库列表
ergo plugin repo list
[info] 上次变更时间: 2021-10-13 15:37:18.782145 +0800 CST
NAME URL
local https://gitee.com/ysbot/ergoplugindemo/raw/master/default.yaml

# 列出远程插件
ergo plugin ls-remote
[done] √ "local"已经更新索引: /Users/ysicing/.ergo/.config/local.index.yaml
[done] √ sync done.
Repo NAME URL Desc Available
local demo-linux https://gitee.com/ysbot/ergoplugindemo/raw/master/demo demo false
local demo-darwin https://gitee.com/ysbot/ergoplugindemo/raw/master/demo demo true
```

#### 其他开源项目

> 感谢以下项目
- [sealos](https://github.com/fanux/sealos)
- [zzz](https://github.com/sohaha/zzz)
- [devspace](https://github.com/loft-sh/devspace)
- [CDK](https://github.com/cdk-team/CDK)
- [kubectl](https://k8s.io/kubectl)
- [loft-sh/devspace](https://github.com/loft-sh/devspace)
- [cdk-team/CDK](https://github.com/cdk-team/CDK)
- [kubernetes/kubectl](https://github.com/kubernetes/kubernetes)
- [helm/helm](https://github.com/helm/helm)

## 🎉🎉 赞助商

Expand Down
1 change: 1 addition & 0 deletions cmd/boot/boot.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ var rootDirs = []string{
common.DefaultDataDir,
common.DefaultDumpDir,
common.DefaultBinDir,
common.DefaultCfgDir,
}

func initRootDirectory() error {
Expand Down
116 changes: 116 additions & 0 deletions cmd/cloud.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
/*
* Copyright (c) 2021 ysicing <i@ysicing.me>
*/

package cmd

import (
"context"
"fmt"
"github.com/ergoapi/util/file"
"github.com/gosuri/uitable"
"github.com/manifoldco/promptui"
"github.com/spf13/cobra"
"github.com/ysicing/ergo/common"
"github.com/ysicing/ergo/pkg/ergo/cloud"
"github.com/ysicing/ergo/pkg/ergo/cloud/aliyun"
"github.com/ysicing/ergo/pkg/ergo/cloud/qcloud"
"github.com/ysicing/ergo/pkg/util/factory"
"helm.sh/helm/v3/pkg/cli/output"
"os"
"sigs.k8s.io/yaml"
)

// NewCloudCommand 云服务商支持
func newCloudCommand(f factory.Factory) *cobra.Command {
cloud := &cobra.Command{
Use: "cloud [flags]",
Short: "云服务商支持",
}
cloud.AddCommand(newCloudCofig(f))
cloud.AddCommand(newCloudDns(f))
return cloud
}

func newCloudCofig(f factory.Factory) *cobra.Command {
cmd := &cobra.Command{}
return cmd
}

func newCloudDns(f factory.Factory) *cobra.Command {
cmd := &cobra.Command{
Use: "dns [flags]",
Short: "dns",
}
cmd.AddCommand(newDnsList(f))
return cmd
}

func newDnsList(f factory.Factory) *cobra.Command {
l := f.GetLog()
cmd := &cobra.Command{
Use: "domain",
Short: "域名列表",
Run: func(cobraCmd *cobra.Command, args []string) {
templates := &promptui.SelectTemplates{
Label: "{{ . }}",
Active: "\U0001F449 {{ .Value | cyan }}",
Inactive: " {{ .Value | cyan }}",
Selected: "\U0001F389 {{ .Value | red | cyan }}",
}
cloudprompt := promptui.Select{
Label: "选择云服务商",
Items: cloud.CloudType,
Size: 4,
Templates: templates,
}
selectid, _, _ := cloudprompt.Run()
ct := cloud.CloudType[selectid]
var domainlist cloud.DomainList
if ct.Key == "all" || ct.Key == cloud.ProviderQcloud.Value() {
l.Debugf("load qcloud domain")
// 腾讯云
p, err := qcloud.NewDns(qcloud.WithLog(l), qcloud.WithApi(os.Getenv("TX_Key"), os.Getenv("TX_Secret")))
if err != nil {
l.Errorf("create qcloud api client err: %v", err)
} else {
pd, err := p.DomainList(context.Background())
if err == nil {
domainlist = append(domainlist, pd...)
} else {
l.Errorf("do qcloud dns api err: %v", err)
}
}
}
if ct.Key == "all" || ct.Key == cloud.ProviderAliyun.Value() {
l.Debugf("load aliyun domain")
// 阿里云
p, err := aliyun.NewDns(aliyun.WithLog(l), aliyun.WithApi(os.Getenv("Ali_Key"), os.Getenv("Ali_Secret")))
if err != nil {
l.Errorf("create aliyun api client err: %v", err)
} else {
pd, err := p.DomainList(context.Background())
if err == nil {
domainlist = append(domainlist, pd...)
} else {
l.Errorf("do aliyun dns api err: %v", err)
}
}
}
table := uitable.New()
table.AddRow("服务商", "域名")
for _, re := range domainlist {
table.AddRow(re.Provider, re.Name)
}
output.EncodeTable(os.Stdout, table)
domainfile := fmt.Sprintf("%v/.domain", common.GetDefaultCfgDir())
if file.CheckFileExists(domainfile) {
file.RemoveFiles(domainfile)
}
resp, _ := yaml.Marshal(domainlist)
file.Writefile(domainfile, string(resp))
l.Donef("域名缓存成功: %v", domainfile)
},
}
return cmd
}
71 changes: 71 additions & 0 deletions cmd/code.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*
* Copyright (c) 2021 ysicing <i@ysicing.me>
*/

package cmd

import (
"github.com/manifoldco/promptui"
"github.com/spf13/cobra"
"github.com/ysicing/ergo/pkg/ergo/codegen"
"github.com/ysicing/ergo/pkg/util/factory"
"github.com/ysicing/ergo/pkg/util/log"
"strings"
)

type CodeOptions struct {
Log log.Logger
}

func newCodeGenCmd(f factory.Factory) *cobra.Command {
c := &CodeOptions{
Log: f.GetLog(),
}
cmd := &cobra.Command{
Use: "code [flags]",
Short: "初始化项目",
Run: func(cobraCmd *cobra.Command, args []string) {
c.Init()
},
}
return cmd
}

func (code CodeOptions) Init() {
searcher := func(input string, index int) bool {
p := codegen.CodeType[index]
name := strings.Replace(strings.ToLower(p.Key), " ", "", -1)
input = strings.Replace(strings.ToLower(input), " ", "", -1)
return strings.Contains(name, input)
}
templates := &promptui.SelectTemplates{
Label: "{{ . }}",
Active: "\U0001F449 {{ .Key | cyan }}",
Inactive: " {{ .Key | cyan }}",
Selected: "\U0001F389 {{ .Key | red | cyan }}",
}
codetype := promptui.Select{
Label: "选择代码类型",
Items: codegen.CodeType,
Searcher: searcher,
Size: 4,
Templates: templates,
}
codetypeid, _, _ := codetype.Run()
selectcodetypevalue := codegen.CodeType[codetypeid].Key
code.Log.Infof("\U0001F389 选择 %v", selectcodetypevalue)
codefunc := codegen.CodeGen{Log: code.Log}
if selectcodetypevalue == "go" {
code.Log.Infof("Start downloading the template...")
if err := codefunc.GoClone(); err != nil {
code.Log.Fatal(err)
return
}
} else {
code.Log.Infof("Start Gen Crds template...")
if err := codefunc.GenCrds(); err != nil {
code.Log.Fatal(err)
return
}
}
}
Loading

0 comments on commit 31d8d69

Please sign in to comment.