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

delete: handle nested objects #23

Merged
merged 2 commits into from
Feb 15, 2025

Conversation

ryan-ph
Copy link
Contributor

@ryan-ph ryan-ph commented Feb 15, 2025

  • delete: refactor iteration
    This refactors the implementation of HclDeleter to make it
    non-destructive. This is important for if / when wildcards are supported
    as we'll need to backtrack through the fields if the wildcard is not
    placed as the final part in the query.

  • delete: handle nested objects
    This handles deletion from nested objects. Given the following terraform
    file

    local {
      obj = {
        obj2 = {
          val = 5
        }
      }
    }

    and the following delete query, hq delete .local.obj.obj2.val, the
    previous behavior outputs:

    local {
      obj = {}
    }

    The new behavior outputs:

    local {
      obj = {
        obj2 = {}
      }
    }

This refactors the implementation of `HclDeleter` to make it
non-destructive. This is important for if / when wildcards are supported
as we'll need to backtrack through the fields if the wildcard is not
placed as the final part in the query.
@ryan-ph ryan-ph changed the title ryanpham/delete/nested object delete: handle nested objects Feb 15, 2025
This handles deletion from nested objects. Given the following terraform
file

```hcl
local {
  obj = {
    obj2 = {
      val = 5
    }
  }
}
```

and the following delete query, `hq delete .local.obj.obj2.val`, the
previous behavior outputs:

```hcl
local {
  obj = {}
}
```

The new behavior outputs:
```hcl
local {
  obj = {
    obj2 = {}
  }
}
```
@ryan-ph ryan-ph force-pushed the ryanpham/delete/nested-object branch from 704c30a to b3a4666 Compare February 15, 2025 07:55
@miller-time
Copy link
Owner

@ryan-ph wow, really nice work!

@miller-time miller-time merged commit de930e2 into miller-time:main Feb 15, 2025
1 check passed
@miller-time
Copy link
Owner

released this in v0.19.1

@ryan-ph ryan-ph deleted the ryanpham/delete/nested-object branch February 18, 2025 04:23
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