Skip to content

Commit 949b420

Browse files
authored
Merge pull request #1 from luopengift/v1.0.0
v1.0.1-release
2 parents 03569f8 + 5849940 commit 949b420

File tree

6 files changed

+48
-47
lines changed

6 files changed

+48
-47
lines changed

cmd/exec.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ func Run(ctx context.Context, conf *config.Config) error {
2626
fmt.Println(version.VERSION)
2727
return nil
2828
case params.Debug:
29-
log.Display("params", params)
30-
log.Display("config", conf)
29+
log.Warn("params: %v", string(log.Dump(params)))
30+
log.Warn("config: %v", string(log.Dump(conf)))
3131
return nil
3232
case len(os.Args) < 3: //登录交互模式
3333
if conf.Remote { // 远程获取模式

console/console.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,9 +156,9 @@ func StartConsole(ctx context.Context, conf *config.Config) error {
156156
r.Super = true
157157
log.ConsoleWithMagenta("进入Super模式!")
158158
case input == "print config":
159-
log.Display("config", conf)
159+
log.Warn("config: %v", string(log.Dump(conf)))
160160
case input == "print runtime":
161-
log.Display("runtime", r)
161+
log.Warn("runtime: %v", string(log.Dump(r)))
162162
case strings.HasPrefix(input, "dump "): // 存储配置文件
163163
if r.Super {
164164
inputList := strings.Split(input, " ")

pkg/endpoint/endpoints.go

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,15 @@ func (eps Endpoints) Groups(kind string) Groups {
5252
}
5353

5454
// Search search
55-
func (eps Endpoints) Search(search ...string) Endpoints {
56-
result := Endpoints{}
57-
for index, endpoint := range eps {
58-
if FindWithIdx(endpoint, index, search...) {
55+
func (eps Endpoints) Search(querys ...string) Endpoints {
56+
if len(querys) == 1 {
57+
if id, err := strconv.Atoi(querys[0]); err == nil && id <= eps.Len() {
58+
return Endpoints{eps[id]}
59+
}
60+
}
61+
var result Endpoints
62+
for _, endpoint := range eps {
63+
if Find(endpoint.Name, querys...) || Find(endpoint.Host, querys...) || Find(endpoint.IP, querys...) {
5964
result = append(result, endpoint)
6065
}
6166
}
@@ -65,8 +70,8 @@ func (eps Endpoints) Search(search ...string) Endpoints {
6570
// Match match
6671
func (eps Endpoints) Match(match string) Endpoints {
6772
result := Endpoints{}
68-
for index, endpoint := range eps {
69-
if match == strconv.Itoa(index) || match == endpoint.Name || match == endpoint.Host || match == endpoint.IP {
73+
for _, endpoint := range eps {
74+
if match == endpoint.Name || match == endpoint.Host || match == endpoint.IP {
7075
result = append(result, endpoint)
7176
}
7277
}

pkg/endpoint/groups.go

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,13 @@ func (grps Groups) Print() {
2828

2929
// Search search
3030
func (grps Groups) Search(querys ...string) Groups {
31-
var result Groups
32-
for index, group := range grps {
33-
if len(querys) == 1 {
34-
if querys[0] == strconv.Itoa(index) {
35-
result = append(result, group)
36-
continue
37-
}
31+
if len(querys) == 1 {
32+
if id, err := strconv.Atoi(querys[0]); err == nil && id <= grps.Len() {
33+
return Groups{grps[id]}
3834
}
39-
35+
}
36+
var result Groups
37+
for _, group := range grps {
4038
if Find(group.Name, querys...) {
4139
result = append(result, group)
4240
}

pkg/endpoint/users.go

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,40 +13,51 @@ var userFormat = "%-4v\t%-20s"
1313
type Users []string
1414

1515
// Print print users
16-
func (s Users) Print() {
16+
func (u Users) Print() {
1717
log.ConsoleWithGreen(fmt.Sprintf(userFormat, "[ID]", "用户名"))
18-
for idx, user := range s {
18+
for idx, user := range u {
1919
log.ConsoleWithGreen(userFormat, fmt.Sprintf("[%v]", idx), user)
2020
}
2121
}
2222

2323
// Search search
24-
func (s Users) Search(querys ...string) Users {
25-
var result Users
26-
for index, user := range s {
27-
if len(querys) == 1 {
28-
if querys[0] == strconv.Itoa(index) {
29-
result = append(result, user)
30-
continue
31-
}
24+
func (u Users) Search(querys ...string) Users {
25+
if len(querys) == 1 {
26+
if id, err := strconv.Atoi(querys[0]); err == nil && id <= u.Len() {
27+
return Users{u[id]}
3228
}
33-
34-
if Find(user, querys...) {
29+
}
30+
var result Users
31+
for _, user := range u {
32+
if FindOr(user, querys...) {
3533
result = append(result, user)
36-
3734
}
38-
3935
}
4036
return result
4137
}
4238

4339
// Match Match
44-
func (s Users) Match(input string) Users {
40+
func (u Users) Match(input string) Users {
4541
var result Users
46-
for index, user := range s {
42+
for index, user := range u {
4743
if input == strconv.Itoa(index) || user == input {
4844
result = append(result, user)
4945
}
5046
}
5147
return result
5248
}
49+
50+
// Len implements sort.Interface
51+
func (u Users) Len() int {
52+
return len(u)
53+
}
54+
55+
// Less implements sort.Interface
56+
func (u Users) Less(i, j int) bool {
57+
return u[i] < u[j]
58+
}
59+
60+
// Swap implements sort.Interface
61+
func (u Users) Swap(i, j int) {
62+
u[i], u[j] = u[j], u[i]
63+
}

pkg/endpoint/util.go

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,9 @@
11
package endpoint
22

33
import (
4-
"strconv"
54
"strings"
6-
7-
"github.com/luopengift/ssh"
85
)
96

10-
// FindWithIdx find
11-
func FindWithIdx(endpoint *ssh.Endpoint, idx int, querys ...string) bool {
12-
if len(querys) == 1 {
13-
if querys[0] == strconv.Itoa(idx) {
14-
return true
15-
}
16-
}
17-
return endpoint.Find(querys...)
18-
}
19-
207
// FindOr find key is contains in one of querys.
218
func FindOr(key string, querys ...string) bool {
229
for _, query := range querys {

0 commit comments

Comments
 (0)