diff --git a/internal/commands/buildpack_new.go b/internal/commands/buildpack_new.go index 6904658ce..9ee62679f 100644 --- a/internal/commands/buildpack_new.go +++ b/internal/commands/buildpack_new.go @@ -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 { diff --git a/internal/target/parse.go b/internal/target/parse.go index dda23b84c..7efc079c7 100644 --- a/internal/target/parse.go +++ b/internal/target/parse.go @@ -32,7 +32,7 @@ func ParseTarget(t string) (output dist.Target, warn warn.Warn, err error) { if err != nil { return output, warn, err } - os, arch, variant,w, err := getPlatform(nonDistro) + os, arch, variant, w, err := getPlatform(nonDistro) warn.AddWarn(w) if err != nil { return output, warn, err @@ -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) + } + 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 { diff --git a/internal/target/parse_test.go b/internal/target/parse_test.go index 3c15cb24c..541263fb9 100644 --- a/internal/target/parse_test.go +++ b/internal/target/parse_test.go @@ -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", @@ -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:ubuntu@22.04;debian@8.10@10.06"}) + output, _, err := target.ParseTargets([]string{"linux/arm/v6", "linux/amd64:ubuntu@22.04;debian@8.10@10.06"}) h.AssertNil(t, err) h.AssertEq(t, output, []dist.Target{ { diff --git a/internal/warn/warn.go b/internal/warn/warn.go index e4b6a65d1..07829f0c3 100644 --- a/internal/warn/warn.go +++ b/internal/warn/warn.go @@ -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 -} \ No newline at end of file +func (warn *Warn) AddWarn(w Warn) { + warn.Messages = append(warn.Messages, w.Messages...) +}