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

Add attribute append command #14

Merged
merged 1 commit into from
Oct 28, 2020
Merged

Add attribute append command #14

merged 1 commit into from
Oct 28, 2020

Conversation

minamijoyo
Copy link
Owner

@minamijoyo minamijoyo commented Oct 27, 2020

In #8, I added block append command. However it can add only an empty body for simplicity. Of course, that's not make sense.
In this PR, I also added attribute append command, which is a missing parts for appending a new block in a real use-case.

It allows us to append a new attribute to a given address.
If a matched block not found, nothing happens.
If the given attribute already exists, it returns an error.
If a newline flag is true, it also appends a newline before the new attribute.

$ go run main.go attribute append --help
Append a new attribute at a given address

Arguments:
  ADDRESS          An address of attribute to append.
  VALUE            A new value of attribute.
                   The value is set literally, even if references or expressions.
                   Thus, if you want to set a string literal "hoge", be sure to
                   escape double quotes so that they are not discarded by your shell.
                   e.g.) hcledit attribute append aaa.bbb.ccc '"hoge"'

Usage:
  hcledit attribute append <ADDRESS> <VALUE> [flags]

Flags:
  -h, --help      help for append
      --newline   Append a new line before a new attribute
$ cat tmp/attr.hcl
resource "foo" "bar" {
  attr1 = "val1"
  nested {
    attr2 = "val2"
  }
}
$ cat tmp/attr.hcl | go run main.go attribute append resource.foo.bar.nested.attr3 '"val3"' --newline
resource "foo" "bar" {
  attr1 = "val1"
  nested {
    attr2 = "val2"

    attr3 = "val3"
  }
}

@minamijoyo minamijoyo force-pushed the add-attribute-append branch 2 times, most recently from d00ac56 to f94d366 Compare October 28, 2020 01:19
In #8, I added block append command. However it can add only an empty
body for simplicity. Of course, that's not make sense. In this patch, I
also added attribute append command, which is a missing parts for
appending a new block in a real use-case.

It allows us to append a new attribute to a given address.
If a matched block not found, nothing happens.
If the given attribute already exists, it returns an error.
If a newline flag is true, it also appends a newline before the new attribute.
@minamijoyo minamijoyo changed the title [WIP] Add attribute append command Add attribute append command Oct 28, 2020
@minamijoyo minamijoyo merged commit abc7527 into master Oct 28, 2020
@minamijoyo minamijoyo deleted the add-attribute-append branch October 28, 2020 01:32
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.

1 participant