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

More examples #171

Closed
rhtenhove opened this issue Oct 20, 2021 · 10 comments · Fixed by #180
Closed

More examples #171

rhtenhove opened this issue Oct 20, 2021 · 10 comments · Fixed by #180
Labels
enhancement New feature or request

Comments

@rhtenhove
Copy link
Contributor

rhtenhove commented Oct 20, 2021

When trying to select from more complex files, I'm at a loss on what's possible, and keep failing at creating a proper query.

Take the following yaml:

---
plugins:
  - "@semantic-release/commit-analyzer"
  - "@semantic-release/release-notes-generator"
  - "@semantic-release/gitlab"
  - - "@semantic-release/git"
    - assets:
        - "tbump.toml"
        - "**/pyproject.toml"
        - "**/setup.py"
        - README.md
      message: |-
        chore(release): ${nextRelease.version}

        ${nextRelease.notes}

I would like to retrieve the list under assets. How would I write a query to achieve this?

Some more examples of all the selector features in the documenation would probably help achieve this.

When converted to json, I can get it using dasel -f .releaserc -r json '.plugins.[3].[1].assets', but that would require a consistent ordering, which isn't guaranteed.

@rhtenhove rhtenhove added the enhancement New feature or request label Oct 20, 2021
@TomWright
Copy link
Owner

The issue here is that dasel expects each item within the plugins list to be of the same type, when in reality the first 3 are strings, and the 4th is is a list.

I can update the dynamic selector to be able to handle type checks.

Let me work on a quick POC for this to validate the use-case and solution.

@TomWright
Copy link
Owner

The customisation I'm working on will give you the ability to do the following:

dasel  -f .releaserc -r yaml -w json -m '.plugins.([@]=array).([@]=map).(-=assets)'
- tbump.toml
- '**/pyproject.toml'
- '**/setup.py'
- README.md

In English this means,

  1. Find any items within the plugins array that are of type array.
  2. Find me any items within that array that are of type map.
  3. Find me any properties within that map that have a key of assets.

As an aside, if you just want to find any item anywhere within your file that has a key of assets, you could do the following already using the saerch selector.

$ dasel -f .releaserc -r yaml -m '.plugins.(?:-=assets)'                             
- tbump.toml
- '**/pyproject.toml'
- '**/setup.py'
- README.md

@TomWright TomWright linked a pull request Nov 3, 2021 that will close this issue
@TomWright
Copy link
Owner

Another example:

dasel -f .releaserc -r yaml '.plugins.([@]=array)([0]=@semantic-release/git).[1].assets'

It searches for a plugin item that is an array where the first item in the array is equal to @semantic-release/git

@TomWright
Copy link
Owner

I'm going to do a bit more testing on my branch and then I'll merge. This will likely go out in the next release.

@rhtenhove
Copy link
Contributor Author

Gave this a try locally, and works wonders, thanks for the improvements!

@TomWright
Copy link
Owner

This is merged to master now but is not in a tagged release yet. It will be going out in the next release though 👍

@TomWright
Copy link
Owner

This is released as of v1.22.0.

@TomWright TomWright reopened this Nov 9, 2021
@rhtenhove
Copy link
Contributor Author

I've tried to upgrade this one to v2, and came up with the following monstrosity:

dasel -f .releaserc -r json ".plugins.all().filter(equal(type(),array)).[1].as
sets"

It makes some assumptions on the structure, such as the order in the nested array, but my main question is, can it be written more concise?

@TomWright
Copy link
Owner

---
plugins:
  - "@semantic-release/commit-analyzer"
  - "@semantic-release/release-notes-generator"
  - "@semantic-release/gitlab"
  - - "@semantic-release/git"
    - assets:
        - "tbump.toml"
        - "**/pyproject.toml"
        - "**/setup.py"
        - README.md
      message: |-
        chore(release): ${nextRelease.version}

        ${nextRelease.notes}

I can't say this is much nicer, but it will at-least work if the ordering is changed around:

$ echo '---
plugins:
  - "@semantic-release/commit-analyzer"
  - "@semantic-release/release-notes-generator"
  - "@semantic-release/gitlab"
  - - "@semantic-release/git"
    - assets:
        - "tbump.toml"
        - "**/pyproject.toml"
        - "**/setup.py"
        - README.md
      message: |-
        chore(release): ${nextRelease.version}

        ${nextRelease.notes}' | dasel -r yaml 'plugins.all().filter(equal(type(),array)).all().filter(equal(type(),object)).assets?'
- tbump.toml
- '**/pyproject.toml'
- '**/setup.py'
- README.md
- ```

@rhtenhove
Copy link
Contributor Author

Excellent, thank you! It's working wonders.

I've also seen your comment in #352, and I'm using this for an append() to that list which is working nicely.

Thanks again!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants