Skip to content

Conversation

@jaypipes
Copy link
Collaborator

@jaypipes jaypipes commented Dec 8, 2021

Adds a few utility methods to pkg/fieldpath.Path to make it easier to
inspect associated ShapeRefs at different parts of the path:

  • Path.At(int) returns the path part at the supplied index.
  • Path.CopyAt(int) returns a new Path up to the supplied index.
  • Path.ShapeRefAt(*shapeRef, int) returns a ShapeRef corresponding to
    the path part at the supplied index.
  • Path.IterShapeRefs(*shapeRef) returns a slice of *ShapeRef that can
    be used to iterate over the ShapeRefs associated with each of the
    Path's parts.

Signed-off-by: Jay Pipes jaypipes@gmail.com

By submitting this pull request, I confirm that my contribution is made under
the terms of the Apache 2.0 license.

Copy link
Member

@a-hilaly a-hilaly left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @jaypipes!

@a-hilaly
Copy link
Member

a-hilaly commented Dec 8, 2021

/test s3-controller-test

Copy link
Contributor

@vijtrip2 vijtrip2 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/approve

// At returns the part of the Path at the supplied index, or empty string if
// index exceeds boundary.
func (p *Path) At(index int) string {
if index < 0 || len(p.parts) < 0 || index > len(p.parts)-1 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit:

Suggested change
if index < 0 || len(p.parts) < 0 || index > len(p.parts)-1 {
if index < 0 || len(p.parts) == 0 || index > len(p.parts)-1 {

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

doh. copy/pasta mistake on my part. nice catch! fixed.

// e.g. given Path $A containing "X.Y", $A.CopyAt(0) would return a new Path
// containing just "X". $A.CopyAt(1) would return a new Path containing "X.Y".
func (p *Path) CopyAt(index int) *Path {
if index < 0 || len(p.parts) < 0 || index > len(p.parts)-1 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: I think length function will never return less than 0. You can just check for empty i.e." == 0"

Suggested change
if index < 0 || len(p.parts) < 0 || index > len(p.parts)-1 {
if index < 0 || len(p.parts) == 0 || index > len(p.parts)-1 {

Adds a few utility methods to `pkg/fieldpath.Path` to make it easier to
inspect associated ShapeRefs at different parts of the path:

* `Path.At(int)` returns the path part at the supplied index.
* `Path.CopyAt(int)` returns a new Path up to the supplied index.
* `Path.ShapeRefAt(*shapeRef, int)` returns a ShapeRef corresponding to
  the path part at the supplied index.
* `Path.IterShapeRefs(*shapeRef)` returns a slice of *ShapeRef that can
  be used to iterate over the ShapeRefs associated with each of the
  Path's parts.

Signed-off-by: Jay Pipes <jaypipes@gmail.com>
@vijtrip2
Copy link
Contributor

vijtrip2 commented Dec 8, 2021

/lgtm

@ack-bot ack-bot added the lgtm Indicates that a PR is ready to be merged. label Dec 8, 2021
@ack-bot
Copy link
Collaborator

ack-bot commented Dec 8, 2021

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: A-Hilaly, jaypipes, vijtrip2

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:
  • OWNERS [A-Hilaly,jaypipes,vijtrip2]

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@ack-bot ack-bot merged commit 26e5da2 into aws-controllers-k8s:main Dec 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved lgtm Indicates that a PR is ready to be merged.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants