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: Support merging Object attributes #9

Open
bbckr opened this issue Oct 21, 2024 · 0 comments
Open

feat: Support merging Object attributes #9

bbckr opened this issue Oct 21, 2024 · 0 comments
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@bbckr
Copy link
Contributor

bbckr commented Oct 21, 2024

Currently the library only supports merging hcl Blocks and nested Blocks recursively. When it comes to attributes (in setAttrs), this is all or nothing, which means both objects and arrays are replaced entirely w/o attempting to merge.

Attributes are represented as a list of hcl Tokens, so in order to merge attributes, we need to be able to parse the list of Tokens to make sense of the type of value we are dealing with.

Acceptance criteria:

  • Be able to recursively merge nested objects
  • Any MR should have this (or a similar) test case added to hcl_test.go:
	tests := []struct {
		name    string
		input   input
		want    string
		wantErr error
	}{
		{
			name: "merge nested duplicate",
			input: input{
				a: `module "b" {

	c = {
		"foo" = {
			value = 1
		},
	}
}
			`,
				b: `module "b" {

	c = {
		"bar" = {
			value = 2
		},
	}
}
			`,
			},
			want: `module "b" {

	c = {
		"foo" = {
			value = 1
		},
		"bar" = {
			value = 2
		},
	}
}
`,
		},
	}
@bbckr bbckr added enhancement New feature or request good first issue Good for newcomers labels Oct 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

1 participant