* added option to exclude binaries from gup update#86
* added option to exclude binaries from gup update#86nao1215 merged 1 commit intonao1215:mainfrom hu3bi:exclude
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.
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 | |
| } |
nao1215
left a comment
There was a problem hiding this comment.
@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 |
| } | ||
| 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.
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.
I might be better, I just never used cobra and didn't take the time to read through the docu.
No description provided.