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

Question: Length/end of an object/array element #2308

Open
fearphage opened this issue Mar 1, 2025 · 0 comments
Open

Question: Length/end of an object/array element #2308

fearphage opened this issue Mar 1, 2025 · 0 comments

Comments

@fearphage
Copy link

Background/Use Case

So I'm doing some checks in a pull request and I need to know the line numbers of the current object/array element. I know which lines in the file have changed and I need to compare that list to the lines of an element to see how they should affect the outcome of a check. For instance if I find an error on a line that was not changed in the current pull request, I'd label that issue a warning instead of an error.

For clarity, I'm checking the contents of YAML that I'm not responsible for writing so I have no control over it. I'm just responsible for writing the checks to validate the contents of the files.

Sample YAML:

catpants:
  - start: end
    value: stuff
    other: |
       Things are here too
        Look at it go!
  - another: one
    value: here
    last: sample

Question

I know how to use key | line to obtain the first line of an element, but is there a way to obtain the "length"/end of an element?

So for this example, I can see the first element of catpants spans from lines 2 through 6 counting manually. Is there a programmatic way that yq can determine where it ends? I was thinking of getting the index of the current element (which makes sense for arrays, but not sure how this would work for an object). But I'm also not sure that I can jump into a sequence and then query the current index -- is that possible? I couldn't find anything related in the docs. I'm open to alternative solutions as well.

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

No branches or pull requests

1 participant