Skip to content

Commit

Permalink
Use plural targets for varargs.
Browse files Browse the repository at this point in the history
  • Loading branch information
mitchell-as committed Oct 8, 2024
1 parent bdf9fd5 commit b17383d
Showing 1 changed file with 19 additions and 19 deletions.
38 changes: 19 additions & 19 deletions pkg/buildscript/queries.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ func (r UnknownRequirement) IsRequirement() {}

// Returns the requirements for the given target.
// If no target is given, uses the default target (i.e. the name assigned to 'main').
func (b *BuildScript) Requirements(target ...string) ([]Requirement, error) {
requirementsNode, err := b.getRequirementsNode(target...)
func (b *BuildScript) Requirements(targets ...string) ([]Requirement, error) {
requirementsNode, err := b.getRequirementsNode(targets...)
if err != nil {
return nil, errs.Wrap(err, "Could not get requirements node")
}
Expand Down Expand Up @@ -99,8 +99,8 @@ func (b *BuildScript) Requirements(target ...string) ([]Requirement, error) {
// DependencyRequirements is identical to Requirements except that it only considers dependency type requirements,
// which are the most common.
// ONLY use this when you know you only need to care about dependencies.
func (b *BuildScript) DependencyRequirements(target ...string) ([]types.Requirement, error) {
reqs, err := b.Requirements(target...)
func (b *BuildScript) DependencyRequirements(targets ...string) ([]types.Requirement, error) {
reqs, err := b.Requirements(targets...)
if err != nil {
return nil, errs.Wrap(err, "Could not get requirements")
}
Expand All @@ -113,8 +113,8 @@ func (b *BuildScript) DependencyRequirements(target ...string) ([]types.Requirem
return deps, nil
}

func (b *BuildScript) getRequirementsNode(target ...string) (*Value, error) {
node, err := b.getSolveNode(target...)
func (b *BuildScript) getRequirementsNode(targets ...string) (*Value, error) {
node, err := b.getSolveNode(targets...)
if err != nil {
return nil, errs.Wrap(err, "Could not get solve node")
}
Expand Down Expand Up @@ -155,14 +155,14 @@ func isSolveFuncName(name string) bool {
return name == solveFuncName || name == solveLegacyFuncName
}

func (b *BuildScript) getTargetSolveNode(target ...string) (*Value, error) {
if len(target) == 0 {
func (b *BuildScript) getTargetSolveNode(targets ...string) (*Value, error) {
if len(targets) == 0 {
for _, assignment := range b.raw.Assignments {
if assignment.Key != mainKey {
continue
}
if assignment.Value.Ident != nil && *assignment.Value.Ident != "" {
target = []string{*assignment.Value.Ident}
targets = []string{*assignment.Value.Ident}
break
}
}
Expand All @@ -177,11 +177,11 @@ func (b *BuildScript) getTargetSolveNode(target ...string) (*Value, error) {
continue
}

if funk.Contains(target, a.Key) && a.Value.FuncCall != nil {
if funk.Contains(targets, a.Key) && a.Value.FuncCall != nil {
return a.Value
}

if f := a.Value.FuncCall; len(target) == 0 && f != nil && isSolveFuncName(f.Name) {
if f := a.Value.FuncCall; len(targets) == 0 && f != nil && isSolveFuncName(f.Name) {
// This is coming from a complex build expression with no straightforward way to determine
// a default target. Fall back on a top-level solve node.
return a.Value
Expand All @@ -202,8 +202,8 @@ func (b *BuildScript) getTargetSolveNode(target ...string) (*Value, error) {
return nil, errNodeNotFound
}

func (b *BuildScript) getSolveNode(target ...string) (*Value, error) {
node, err := b.getTargetSolveNode(target...)
func (b *BuildScript) getSolveNode(targets ...string) (*Value, error) {
node, err := b.getTargetSolveNode(targets...)
if err != nil {
return nil, errs.Wrap(err, "Could not get target node")
}
Expand Down Expand Up @@ -237,8 +237,8 @@ func (b *BuildScript) getSolveNode(target ...string) (*Value, error) {
return nil, errNodeNotFound
}

func (b *BuildScript) getSolveAtTimeValue(target ...string) (*Value, error) {
node, err := b.getSolveNode(target...)
func (b *BuildScript) getSolveAtTimeValue(targets ...string) (*Value, error) {
node, err := b.getSolveNode(targets...)
if err != nil {
return nil, errs.Wrap(err, "Could not get solve node")
}
Expand All @@ -252,8 +252,8 @@ func (b *BuildScript) getSolveAtTimeValue(target ...string) (*Value, error) {
return nil, errValueNotFound
}

func (b *BuildScript) Platforms(target ...string) ([]strfmt.UUID, error) {
node, err := b.getPlatformsNode(target...)
func (b *BuildScript) Platforms(targets ...string) ([]strfmt.UUID, error) {
node, err := b.getPlatformsNode(targets...)
if err != nil {
return nil, errs.Wrap(err, "Could not get platform node")
}
Expand All @@ -265,8 +265,8 @@ func (b *BuildScript) Platforms(target ...string) ([]strfmt.UUID, error) {
return list, nil
}

func (b *BuildScript) getPlatformsNode(target ...string) (*Value, error) {
node, err := b.getSolveNode(target...)
func (b *BuildScript) getPlatformsNode(targets ...string) (*Value, error) {
node, err := b.getSolveNode(targets...)
if err != nil {
return nil, errs.Wrap(err, "Could not get solve node")
}
Expand Down

0 comments on commit b17383d

Please sign in to comment.