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: add getPath/objectHasPath/objectHasPathAll functions for access to nested objects #342

Merged
merged 8 commits into from
Oct 6, 2023

Conversation

jdockerty
Copy link
Member

@jdockerty jdockerty commented Oct 4, 2023

This adds the following functions:

  • getPath(obj, path, default=null, inc_hidden=true)
  • objectHasPath(obj, path, inc_hidden=false)
  • objectHasPathAll(obj, path)

into the kubecfg.libsonnet file.

This is shorthand for needing to do something which looks like this for nested objects:

if std.objectHas(myObj, "foo") && std.objectHas(myObj.foo, "bar") && ...

This was adapted from an old jsonnet mailing list and morphed to be more inline with the standard library implementations for the respective jsonnet functions.

@jdockerty jdockerty self-assigned this Oct 4, 2023
@jdockerty jdockerty changed the title feat: add getAtPath function for nested objects to kubecfg.libsonnet feat: add getAtPath function for nested objects Oct 4, 2023
@jdockerty jdockerty requested a review from mkmik October 4, 2023 13:47
@jdockerty jdockerty changed the title feat: add getAtPath function for nested objects feat: add getAtPath/hasAtPath functions for nested objects Oct 4, 2023
testdata/kubecfg_test.jsonnet Outdated Show resolved Hide resolved
lib/kubecfg.libsonnet Outdated Show resolved Hide resolved
This brings these functions more in line with the standard library, utilising the hidden_fields_wrapper for better readability
@jdockerty jdockerty changed the title feat: add getAtPath/hasAtPath functions for nested objects feat: add getPath/objectHasPath/objectHasPathAll functions for access to nested objects Oct 5, 2023
Copy link
Contributor

@mkmik mkmik left a comment

Choose a reason for hiding this comment

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

LGTM!

@jdockerty jdockerty added the automerge Put in the merge queue label Oct 6, 2023
@kodiakhq kodiakhq bot merged commit d1a5fc4 into main Oct 6, 2023
6 checks passed
@kodiakhq kodiakhq bot deleted the feat/get-at-path-func branch October 6, 2023 12:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
automerge Put in the merge queue
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants