get.porter.sh/porter@v1.3.0/pkg/exec/execute.go (about)

     1  package exec
     2  
     3  import (
     4  	"context"
     5  
     6  	"get.porter.sh/porter/pkg/exec/builder"
     7  	"get.porter.sh/porter/pkg/yaml"
     8  )
     9  
    10  // ExecOptions represent the options for any exec command
    11  type ExecuteOptions struct {
    12  	File string
    13  }
    14  
    15  func (m *Mixin) loadAction(ctx context.Context, commandFile string) (*Action, error) {
    16  	var action Action
    17  	err := builder.LoadAction(ctx, m.Config, commandFile, func(contents []byte) (interface{}, error) {
    18  		err := yaml.Unmarshal(contents, &action)
    19  		return &action, err
    20  	})
    21  	return &action, err
    22  }
    23  
    24  func (m *Mixin) Execute(ctx context.Context, opts ExecuteOptions) error {
    25  	action, err := m.loadAction(ctx, opts.File)
    26  	if err != nil {
    27  		return err
    28  	}
    29  
    30  	_, err = builder.ExecuteSingleStepAction(ctx, m.Config, action)
    31  	return err
    32  }