github.com/tilt-dev/tilt@v0.33.15-0.20240515162809-0a22ed45d8a0/internal/tiltfile/encoding/plugin.go (about)

     1  package encoding
     2  
     3  import "github.com/tilt-dev/tilt/internal/tiltfile/starkit"
     4  
     5  type Plugin struct{}
     6  
     7  func NewPlugin() Plugin {
     8  	return Plugin{}
     9  }
    10  
    11  const (
    12  	readYAMLN         = "read_yaml"
    13  	readYAMLStreamN   = "read_yaml_stream"
    14  	decodeYAMLN       = "decode_yaml"
    15  	decodeYAMLStreamN = "decode_yaml_stream"
    16  	encodeYAMLN       = "encode_yaml"
    17  	encodeYAMLStreamN = "encode_yaml_stream"
    18  
    19  	readJSONN   = "read_json"
    20  	decodeJSONN = "decode_json"
    21  	encodeJSONN = "encode_json"
    22  )
    23  
    24  func (Plugin) OnStart(env *starkit.Environment) error {
    25  	for _, b := range []struct {
    26  		name string
    27  		f    starkit.Function
    28  	}{
    29  		{readYAMLN, readYAML},
    30  		{readYAMLStreamN, readYAMLStream},
    31  		{decodeYAMLN, decodeYAML},
    32  		{decodeYAMLStreamN, decodeYAMLStream},
    33  		{encodeYAMLN, encodeYAML},
    34  		{encodeYAMLStreamN, encodeYAMLStream},
    35  
    36  		{readJSONN, readJSON},
    37  		{decodeJSONN, decodeJSON},
    38  		{encodeJSONN, encodeJSON},
    39  	} {
    40  		err := env.AddBuiltin(b.name, b.f)
    41  		if err != nil {
    42  			return err
    43  		}
    44  	}
    45  
    46  	return nil
    47  }