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

feat(parser): Support relative paths in references #12

Draft
wants to merge 3 commits into
base: develop
Choose a base branch
from

Conversation

MatteoVoges
Copy link

@MatteoVoges MatteoVoges commented Mar 21, 2023

Fixes kapitan issue #706

Proposed Changes

  • Added support for resolving relative paths in references based on its location in the dictionary
  • Added possibility to access the keys name

Keyword reference

To move just one nesting-level back, use ::, an empty key, e.g. ${:::my:key}

To get the name of a key itself, you can use the keyword .self_name as an attribute to your current key, e.g. ${my:key:.self_name}

Full Example

parameters:
  home:
    city: duckburg
  animals:
    duck:
      name: donald
      type: ${:.self_name} # --> duck
    mouse:
      name: mickey
      lives_in: ${:::home:city} # --> duckburg

There shouldn't be any breaking changes!

But if you have any concerns, please let me know.

To Do

  • Add tests
  • Test the feature with multi-nested references, and several-jump references (which location-path gets taken ??? )
    • Extend / fix the functionality if neccessary
    • There are 3 cases for that... I will document these here:
      • ${:relative:${absolute}} works fine
      • The following examples only works for some cases. I will figure out, how to pass the path to every reference!
        parameters:
          values: 
            myvalue: abc
            first: ${:myvalue}
            second: ${:first}
      • ${absolute:${:relative}} doesn't work at the moment. I can't figure out, why the path (the refs location in the dict) sometimes doesn't get passed to the resolving process
  • Add documentation

Contributed by

This allows us to specify relative paths and use some predefined keyword-functions
The keyword '.self_name' was missing its access operator
Handle Indexerror when calling '.self_name' out of range
@MatteoVoges MatteoVoges marked this pull request as draft March 23, 2023 10:15
@gburiola
Copy link

@MatteoVoges. This is really great. I like the :: to go back and .self_name

I don't get the use case for ~ though. Don't we have that already?
In your example above, isn't ${~:home:city} the same as ${home:city}

@MatteoVoges
Copy link
Author

I don't get the use case for ~ though. Don't we have that already? In your example above, isn't ${~:home:city} the same as ${home:city}

You're right. I completely missed that. I have chosen the symbols as in unix and developed it first without thinking of some usecases. I will remove it soon!

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

Successfully merging this pull request may close these issues.

2 participants