-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
(refactor) cmd refactor #22
Changes from 4 commits
da19f3b
d18f289
6c47173
f708113
cab890b
0e24206
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -370,3 +370,23 @@ func sshFilesByPattern(pattern string, config *SSHConfig) ([]string, error) { | |
filePaths := buf.String() | ||
return strings.Split(strings.TrimSpace(filePaths), "\n"), nil | ||
} | ||
|
||
func UniqueFileInfos(fileInfos []FileInfo) []FileInfo { | ||
kevincobain2000 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
keys := make(map[string]bool) | ||
list := []FileInfo{} | ||
for _, entry := range fileInfos { | ||
key := entry.FilePath + entry.Type + entry.Host | ||
if _, value := keys[key]; !value { | ||
keys[key] = true | ||
list = append(list, entry) | ||
} | ||
} | ||
return list | ||
} | ||
|
||
// func UniqueFileInfos(fileInfos []FileInfo) []FileInfo { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You kept them here for a later use ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Removed them. I tested the asis and Tobe first, as there were no tests for that. |
||
// eq := func(a, b FileInfo) bool { | ||
// return a.FilePath == b.FilePath && a.Type == b.Type && a.Host == b.Host | ||
// } | ||
// return slices.CompactFunc(fileInfos, eq) | ||
// } |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package pkg | ||
|
||
type SliceFlags []string | ||
|
||
// provide a String() method on the type so we can use it with flag.Var | ||
func (i *SliceFlags) String() string { | ||
kevincobain2000 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return "" | ||
} | ||
|
||
// provide a Set() method on the type so we can use it with flag.Var | ||
func (i *SliceFlags) Set(value string) error { | ||
kevincobain2000 marked this conversation as resolved.
Show resolved
Hide resolved
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This can't be append, reverting back from Reason:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. indeed, in such case, I always try to add a comment like: // required to implement flag.Value interface |
||
*i = append(*i, value) | ||
return nil | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.