forked from mercari/hcledit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
option.go
42 lines (36 loc) · 1.05 KB
/
option.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package hcledit
type option struct {
comment string
afterKey string
beforeNewline bool
readFallbackToRawString bool
}
// Option configures specific behavior for specific HCLEditor operations.
// TODO(slewiskelly): Not all options are applicable to all operations, maybe
// options should be specific to each kind of operation?
type Option func(*option)
// WithComment provides comment to put together when creating.
func WithComment(comment string) Option {
return func(opt *option) {
opt.comment = comment
}
}
func WithAfter(key string) Option {
return func(opt *option) {
opt.afterKey = key
}
}
// WithNewLine
func WithNewLine() Option {
return func(opt *option) {
opt.beforeNewline = true
}
}
// This provides a fallback to return the raw string of the value if we could
// not parse it. If this option is provided to HCLEditor.Read(), the error
// return value will signal fallback occurred.
func WithReadFallbackToRawString() Option {
return func(opt *option) {
opt.readFallbackToRawString = true
}
}