@@ -8,18 +8,20 @@ import (
8
8
"github.com/manifoldco/promptui"
9
9
"github.com/spf13/cobra"
10
10
"github.com/ysicing/ergo/cmd/flags"
11
- install2 "github.com/ysicing/ergo/pkg/ergo/repo"
11
+ install "github.com/ysicing/ergo/pkg/ergo/repo"
12
12
"github.com/ysicing/ergo/pkg/util/factory"
13
13
sshutil "github.com/ysicing/ergo/pkg/util/ssh"
14
14
"strings"
15
15
)
16
16
17
17
type RepoCmd struct {
18
18
* flags.GlobalFlags
19
- local bool
20
- sshcfg sshutil.SSH
21
- ips []string
22
- output string
19
+ local bool
20
+ sshcfg sshutil.SSH
21
+ ips []string
22
+ output string
23
+ volumes bool
24
+ all bool
23
25
}
24
26
25
27
// newRepoCmd ergo repo tools
@@ -29,7 +31,7 @@ func newRepoCmd(f factory.Factory) *cobra.Command {
29
31
}
30
32
repocmd .sshcfg .Log = f .GetLog ()
31
33
repo := & cobra.Command {
32
- Use : "repo" ,
34
+ Use : "repo [flags] " ,
33
35
Short : "包管理工具" ,
34
36
Args : cobra .NoArgs ,
35
37
Version : "2.0.1" ,
@@ -58,11 +60,22 @@ func newRepoCmd(f factory.Factory) *cobra.Command {
58
60
return repocmd .Dump ()
59
61
},
60
62
}
63
+ down := & cobra.Command {
64
+ Use : "down" ,
65
+ Short : "down" ,
66
+ Version : "2.0.2" ,
67
+ RunE : func (cobraCmd * cobra.Command , args []string ) error {
68
+ return repocmd .Down (args )
69
+ },
70
+ }
61
71
repo .AddCommand (list )
62
72
list .PersistentFlags ().StringVarP (& repocmd .output , "output" , "o" , "" , "prints the output in the specified format. Allowed values: table, json, yaml (default table)" )
63
73
repo .AddCommand (install )
64
74
repo .AddCommand (dump )
65
75
dump .PersistentFlags ().StringVarP (& repocmd .output , "output" , "o" , "" , "dump file, 默认stdout, 支持file" )
76
+ repo .AddCommand (down )
77
+ down .PersistentFlags ().BoolVar (& repocmd .all , "all" , false , "Remove All Package" )
78
+ down .PersistentFlags ().BoolVarP (& repocmd .volumes , "volumes" , "v" , false , "Remove named volumes declared in the volumes section of the Compose file and anonymous volumes attached to containers." )
66
79
repo .PersistentFlags ().StringVar (& repocmd .sshcfg .User , "user" , "root" , "用户" )
67
80
repo .PersistentFlags ().StringVar (& repocmd .sshcfg .Pass , "pass" , "" , "密码" )
68
81
repo .PersistentFlags ().StringVar (& repocmd .sshcfg .PkFile , "pk" , "" , "私钥" )
@@ -73,13 +86,27 @@ func newRepoCmd(f factory.Factory) *cobra.Command {
73
86
}
74
87
75
88
func (repo * RepoCmd ) List () error {
76
- return install2 .ShowPackage (repo .output )
89
+ return install .ShowPackage (repo .output )
90
+ }
91
+
92
+ func (repo * RepoCmd ) Down (args []string ) error {
93
+ if repo .all {
94
+ var n []string
95
+ for _ , p := range install .InstallPackages {
96
+ n = append (n , p .Name )
97
+ }
98
+ return install .DownService (n , repo .volumes )
99
+ }
100
+ if len (args ) == 0 {
101
+ return fmt .Errorf ("参数不全. eg: ergo repo down etcd redis --debug --volumes" )
102
+ }
103
+ return install .DownService (args , repo .volumes )
77
104
}
78
105
79
106
func (repo * RepoCmd ) Dump () error {
80
107
repo .sshcfg .Log .Infof ("开始加载可用安装程序" )
81
108
searcher := func (input string , index int ) bool {
82
- packages := install2 .InstallPackages [index ]
109
+ packages := install .InstallPackages [index ]
83
110
name := strings .Replace (strings .ToLower (packages .Name ), " " , "" , - 1 )
84
111
input = strings .Replace (strings .ToLower (input ), " " , "" , - 1 )
85
112
return strings .Contains (name , input )
@@ -92,7 +119,7 @@ func (repo *RepoCmd) Dump() error {
92
119
}
93
120
prompt := promptui.Select {
94
121
Label : "选择Dump软件包" ,
95
- Items : install2 .InstallPackages ,
122
+ Items : install .InstallPackages ,
96
123
Searcher : searcher ,
97
124
Size : 4 ,
98
125
Templates : templates ,
@@ -101,16 +128,16 @@ func (repo *RepoCmd) Dump() error {
101
128
if err != nil {
102
129
return fmt .Errorf ("选择异常: %v" , err )
103
130
}
104
- pn := install2 .InstallPackages [selectid ].Name
131
+ pn := install .InstallPackages [selectid ].Name
105
132
repo .sshcfg .Log .Infof ("\U0001F389 Dumping %v" , pn )
106
- i := install2 .NewInstall (install2 .Meta {SSH : repo .sshcfg }, pn )
133
+ i := install .NewInstall (install .Meta {SSH : repo .sshcfg }, pn )
107
134
return i .Dump (repo .output )
108
135
}
109
136
110
137
func (repo * RepoCmd ) Install () error {
111
138
repo .sshcfg .Log .Infof ("开始加载可用安装程序" )
112
139
searcher := func (input string , index int ) bool {
113
- packages := install2 .InstallPackages [index ]
140
+ packages := install .InstallPackages [index ]
114
141
name := strings .Replace (strings .ToLower (packages .Name ), " " , "" , - 1 )
115
142
input = strings .Replace (strings .ToLower (input ), " " , "" , - 1 )
116
143
return strings .Contains (name , input )
@@ -129,7 +156,7 @@ func (repo *RepoCmd) Install() error {
129
156
}
130
157
prompt := promptui.Select {
131
158
Label : "选择安装的软件包" ,
132
- Items : install2 .InstallPackages ,
159
+ Items : install .InstallPackages ,
133
160
Searcher : searcher ,
134
161
Size : 4 ,
135
162
Templates : templates ,
@@ -138,9 +165,12 @@ func (repo *RepoCmd) Install() error {
138
165
if err != nil {
139
166
return fmt .Errorf ("选择异常: %v" , err )
140
167
}
141
- pn := install2 .InstallPackages [selectid ].Name
168
+ pn := install .InstallPackages [selectid ].Name
142
169
repo .sshcfg .Log .Infof ("选择安装: %v" , pn )
143
- i := install2 .NewInstall (install2.Meta {SSH : repo .sshcfg , Local : repo .local , IPs : repo .ips }, pn )
170
+ if len (repo .ips ) == 0 && repo .local {
171
+ return fmt .Errorf ("配置ip或者本地调试" )
172
+ }
173
+ i := install .NewInstall (install.Meta {SSH : repo .sshcfg , Local : repo .local , IPs : repo .ips }, pn )
144
174
repo .sshcfg .Log .StartWait (fmt .Sprintf ("开始安装: %v" , pn ))
145
175
defer repo .sshcfg .Log .StopWait ()
146
176
if err := i .Install (); err != nil {
0 commit comments