-
-
Notifications
You must be signed in to change notification settings - Fork 17
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
* added option to exclude binaries from gup update #86
Conversation
func excludePkgs(exclude string, pkgs []goutil.Package) []goutil.Package { | ||
excludelist := strings.Split(exclude, ",") | ||
|
||
for i := len(pkgs) - 1; i >= 0; i-- { | ||
if slice.Contains(excludelist, pkgs[i].Name) { | ||
pkgs = append(pkgs[:i], pkgs[i+1:]...) | ||
} | ||
} | ||
|
||
return pkgs | ||
} |
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.
I would like to make a small modification. The code you wrote uses less memory. However, The following writing style is simpler and easier to read.
func excludePkgs(exclude string, pkgs []goutil.Package) []goutil.Package { | |
excludelist := strings.Split(exclude, ",") | |
for i := len(pkgs) - 1; i >= 0; i-- { | |
if slice.Contains(excludelist, pkgs[i].Name) { | |
pkgs = append(pkgs[:i], pkgs[i+1:]...) | |
} | |
} | |
return pkgs | |
} | |
func excludePkgs(exclude string, pkgs []goutil.Package) []goutil.Package { | |
excludeList := strings.Split(exclude, ",") | |
packageList := []goutil.Package{} | |
for _, v := range pkgs { | |
if slice.Contains(excludeList, v.Name) { | |
continue | |
} | |
packageList = append(packageList, v) | |
} | |
return pkgs | |
} |
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.
@hueuebi
Thank you for the PR.
Codecov Report
@@ Coverage Diff @@
## main #86 +/- ##
==========================================
- Coverage 83.28% 82.79% -0.49%
==========================================
Files 15 15
Lines 676 686 +10
==========================================
+ Hits 563 568 +5
- Misses 82 87 +5
Partials 31 31
📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
@@ -32,6 +33,7 @@ under $GOPATH/bin and automatically updates commands to the latest version.`, | |||
} | |||
cmd.Flags().BoolP("dry-run", "n", false, "perform the trial update with no changes") | |||
cmd.Flags().BoolP("notify", "N", false, "enable desktop notifications") | |||
cmd.Flags().StringP("exclude", "e", "", "specify binaries which should not be updated separated using ',' without spaces as a delimiter") |
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.
Wouldn't it be more convenient to use StringSliceP() instead of StringP() for this code?
https://pkg.go.dev/github.com/spf13/pflag#StringSliceP
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.
I might be better, I just never used cobra and didn't take the time to read through the docu.
No description provided.