...

Source file src/github.com/redhat-developer/odo/pkg/libdevfile/command.go

Documentation: github.com/redhat-developer/odo/pkg/libdevfile

     1  package libdevfile
     2  
     3  import (
     4  	"context"
     5  	"strings"
     6  
     7  	"github.com/devfile/api/v2/pkg/apis/workspaces/v1alpha2"
     8  	"github.com/devfile/library/v2/pkg/devfile/parser"
     9  	"github.com/devfile/library/v2/pkg/devfile/parser/data/v2/common"
    10  
    11  	"github.com/redhat-developer/odo/pkg/util"
    12  )
    13  
    14  type command interface {
    15  	CheckValidity() error
    16  	Execute(ctx context.Context, handler Handler, parentGroup *v1alpha2.CommandGroup) error
    17  }
    18  
    19  // newCommand returns a command implementation, depending on the type of the command
    20  func newCommand(devfileObj parser.DevfileObj, devfileCmd v1alpha2.Command) (command, error) {
    21  	var cmd command
    22  
    23  	commandType, err := common.GetCommandType(devfileCmd)
    24  	if err != nil {
    25  		return nil, err
    26  	}
    27  
    28  	switch commandType {
    29  
    30  	case v1alpha2.ApplyCommandType:
    31  		cmd = newApplyCommand(devfileObj, devfileCmd)
    32  
    33  	case v1alpha2.CompositeCommandType:
    34  		if util.SafeGetBool(devfileCmd.Composite.Parallel) {
    35  			cmd = newParallelCompositeCommand(devfileObj, devfileCmd)
    36  		} else {
    37  			cmd = newCompositeCommand(devfileObj, devfileCmd)
    38  		}
    39  
    40  	case v1alpha2.ExecCommandType:
    41  		cmd = newExecCommand(devfileObj, devfileCmd)
    42  	}
    43  
    44  	if err = cmd.CheckValidity(); err != nil {
    45  		return nil, err
    46  	}
    47  	return cmd, nil
    48  }
    49  
    50  // allCommandsMap returns a map of all commands in the devfile, indexed by Id
    51  func allCommandsMap(devfileObj parser.DevfileObj) (map[string]v1alpha2.Command, error) {
    52  	commands, err := devfileObj.Data.GetCommands(common.DevfileOptions{})
    53  	if err != nil {
    54  		return nil, err
    55  	}
    56  
    57  	commandMap := make(map[string]v1alpha2.Command, len(commands))
    58  	for _, command := range commands {
    59  		commandMap[strings.ToLower(command.Id)] = command
    60  	}
    61  
    62  	return commandMap, nil
    63  }
    64  

View as plain text