-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathoperator.go
43 lines (37 loc) · 1.46 KB
/
operator.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
43
package editor
import (
"github.com/hashicorp/hcl/v2/hclwrite"
)
// Operator is an interface which abstracts stream operations.
// The hcledit provides not only operations for editing HCL,
// but also for deriving such as listing.
// They need similar but different implementations.
type Operator interface {
// Apply reads input bytes, apply some operations, and writes outputs.
// The input and output contain arbitrary bytes (maybe HCL or not).
// Note that a filename is used only for an error message.
Apply(input []byte, filename string) ([]byte, error)
}
// Source is an interface which reads string and writes HCL
type Source interface {
// Source parses HCL and returns *hclwrite.File
// filename is a metadata of input stream and used only for an error message.
Source(src []byte, filename string) (*hclwrite.File, error)
}
// Filter is an interface which reads HCL and writes HCL
type Filter interface {
// Filter reads HCL and writes HCL
Filter(*hclwrite.File) (*hclwrite.File, error)
}
// Sink is an interface which reads HCL and writes bytes.
type Sink interface {
// Sink reads HCL and writes bytes.
Sink(*hclwrite.File) ([]byte, error)
}
// Formatter is an interface which reads HCL, formats tokens and writes bytes.
// Formatter has a signature similar to Sink, but they have different features,
// so we distinguish them with types.
type Formatter interface {
// Format reads HCL, formats tokens and writes bytes.
Format(*hclwrite.File) ([]byte, error)
}