Skip to content
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

Merged
merged 1 commit into from
May 2, 2023
Merged

* added option to exclude binaries from gup update #86

merged 1 commit into from
May 2, 2023

Conversation

hu3bi
Copy link

@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
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
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

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

@@ -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")
Copy link
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
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.

@nao1215 nao1215 merged commit 4d40b63 into nao1215:main May 2, 2023
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