Skip to content

* added option to exclude binaries from gup update#86

Merged
nao1215 merged 1 commit intonao1215:mainfrom
hu3bi:exclude
May 2, 2023
Merged

* added option to exclude binaries from gup update#86
nao1215 merged 1 commit intonao1215:mainfrom
hu3bi:exclude

Conversation

@hu3bi
Copy link
Copy Markdown

@hu3bi hu3bi commented Apr 30, 2023

No description provided.

Comment on lines +91 to +101
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
}
Copy link
Copy Markdown
Owner

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.

Suggested change
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
}

Copy link
Copy Markdown
Owner

@nao1215 nao1215 left a 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
Copy link
Copy Markdown

codecov bot commented Apr 30, 2023

Codecov Report

Merging #86 (2618cc2) into main (0767c39) will decrease coverage by 0.49%.
The diff coverage is 75.00%.

@@            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              
Impacted Files Coverage Δ
cmd/update.go 71.42% <70.00%> (-1.85%) ⬇️
cmd/root.go 100.00% <100.00%> (ø)

📣 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")
Copy link
Copy Markdown
Owner

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

Copy link
Copy Markdown
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants