Skip to content

Commit

Permalink
Update documentation and improve wording
Browse files Browse the repository at this point in the history
  • Loading branch information
mbillow committed Mar 7, 2022
1 parent c647b7b commit 642c62e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
8 changes: 6 additions & 2 deletions docs/templating-language.md
Original file line number Diff line number Diff line change
Expand Up @@ -1601,12 +1601,16 @@ for more information.

### `writeToFile`

Writes the content to a file with username, group name, permissions. There are optional flags to
select appending mode or add a newline.
Writes the content to a file with permissions, username (or UID), group name (or GID),
and optional flags to select appending mode or add a newline.

The username and group name fields can be left blank to default to the current user and group.

For example:

```golang
{{ key "my/key/path" | writeToFile "/my/file/path.txt" "" "" "0644" }}
{{ key "my/key/path" | writeToFile "/my/file/path.txt" "100" "1000" "0644" }}
{{ key "my/key/path" | writeToFile "/my/file/path.txt" "my-user" "my-group" "0644" }}
{{ key "my/key/path" | writeToFile "/my/file/path.txt" "my-user" "my-group" "0644" "append" }}
{{ key "my/key/path" | writeToFile "/my/file/path.txt" "my-user" "my-group" "0644" "append,newline" }}
Expand Down
6 changes: 4 additions & 2 deletions template/funcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -1611,8 +1611,10 @@ func md5sum(item string) (string, error) {
return fmt.Sprintf("%x", md5.Sum([]byte(item))), nil
}

// writeToFile writes the content to a file with permissions and optional username/UID,
// group name/GID, and flags to select appending mode or add a newline.
// writeToFile writes the content to a file with permissions, username (or UID), group name (or GID),
// and optional flags to select appending mode or add a newline.
//
// The username and group name fields can be left blank to default to the current user and group.
//
// For example:
// key "my/key/path" | writeToFile "/my/file/path.txt" "" "" "0644"
Expand Down

0 comments on commit 642c62e

Please sign in to comment.