Skip to content

Commit

Permalink
lint fix
Browse files Browse the repository at this point in the history
Signed-off-by: WYGIN <[email protected]>
  • Loading branch information
WYGIN committed Oct 1, 2023
1 parent 9a5036c commit e7902f8
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 17 deletions.
2 changes: 1 addition & 1 deletion internal/commands/buildpack_new.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func BuildpackNew(logger logging.Logger, creator BuildpackCreator) *cobra.Comman
}

targets, warn, err := target.ParseTargets(flags.Targets)
for _,w := range warn.Messages {
for _, w := range warn.Messages {
logger.Warn(w)
}
if err != nil {
Expand Down
10 changes: 6 additions & 4 deletions internal/target/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func ParseTarget(t string) (output dist.Target, warn warn.Warn, err error) {
if err != nil {
return output, warn, err
}

Check warning on line 34 in internal/target/parse.go

View check run for this annotation

Codecov / codecov/patch

internal/target/parse.go#L33-L34

Added lines #L33 - L34 were not covered by tests
os, arch, variant,w, err := getPlatform(nonDistro)
os, arch, variant, w, err := getPlatform(nonDistro)
warn.AddWarn(w)
if err != nil {
return output, warn, err
Expand Down Expand Up @@ -82,12 +82,14 @@ func ParseDistro(distroString string) (distro dist.Distribution, warn warn.Warn,

func getTarget(t string) (nonDistro []string, distros string, warn warn.Warn, err error) {
target := strings.Split(t, ":")
if i, err := getSliceAt[string](target, 0); err != nil {
if _, err := getSliceAt[string](target, 0); err != nil {
return nonDistro, distros, warn, errors.Errorf("invalid target %s, atleast one of [os][/arch][/archVariant] must be specified", t)
} else if len(target) == 2 && target[0] == "" {
v,_ := getSliceAt[string](target, 1)
}

Check warning on line 87 in internal/target/parse.go

View check run for this annotation

Codecov / codecov/patch

internal/target/parse.go#L86-L87

Added lines #L86 - L87 were not covered by tests
if len(target) == 2 && target[0] == "" {
v, _ := getSliceAt[string](target, 1)
warn.Add(style.Warn("adding distros %s without [os][/arch][/variant]", v))
} else {
i, _ := getSliceAt[string](target, 0)
nonDistro = strings.Split(i, "/")
}
if i, err := getSliceAt[string](target, 1); err == nil {
Expand Down
6 changes: 3 additions & 3 deletions internal/target/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func testParseTargets(t *testing.T, when spec.G, it spec.S) {
h.AssertNotNil(t, warn.Messages)
})
it("should parse target as expected", func() {
output,_, err := target.ParseTarget("linux/arm/v6")
output, _, err := target.ParseTarget("linux/arm/v6")
h.AssertNil(t, err)
h.AssertEq(t, output, dist.Target{
OS: "linux",
Expand All @@ -41,11 +41,11 @@ func testParseTargets(t *testing.T, when spec.G, it spec.S) {
})
when("target#ParseTargets", func() {
it("should throw an error when atleast one target throws error", func() {
_,_, err := target.ParseTargets([]string{"linux/arm/v6", ":distro@version"})
_, _, err := target.ParseTargets([]string{"linux/arm/v6", ":distro@version"})
h.AssertNotNil(t, err)
})
it("should parse targets as expected", func() {
output,_, err := target.ParseTargets([]string{"linux/arm/v6", "linux/amd64:[email protected];[email protected]@10.06"})
output, _, err := target.ParseTargets([]string{"linux/arm/v6", "linux/amd64:[email protected];[email protected]@10.06"})
h.AssertNil(t, err)
h.AssertEq(t, output, []dist.Target{
{
Expand Down
15 changes: 6 additions & 9 deletions internal/warn/warn.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,14 @@ type Warn struct {
Messages []string
}

func(warn Warn) Add(mesage string) Warn {
warn.Messages = append(warn.Messages, mesage)
return warn
func (warn *Warn) Add(message string) {
warn.Messages = append(warn.Messages, message)
}

func(warn Warn) AddSlice(messages... string) Warn {
func (warn *Warn) AddSlice(messages ...string) {
warn.Messages = append(warn.Messages, messages...)
return warn
}

func(w Warn) AddWarn(warn Warn) Warn {
w.Messages = append(w.Messages, warn.Messages...)
return w
}
func (warn *Warn) AddWarn(w Warn) {
warn.Messages = append(warn.Messages, w.Messages...)
}

0 comments on commit e7902f8

Please sign in to comment.