...

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

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

     1  package libdevfile
     2  
     3  import (
     4  	"context"
     5  
     6  	"github.com/devfile/api/v2/pkg/apis/workspaces/v1alpha2"
     7  	"github.com/devfile/library/v2/pkg/devfile/parser"
     8  )
     9  
    10  // execCommand is a command implementation for exec commands
    11  type execCommand struct {
    12  	command    v1alpha2.Command
    13  	devfileObj parser.DevfileObj
    14  }
    15  
    16  var _ command = (*execCommand)(nil)
    17  
    18  // newExecCommand creates a new execCommand instance, adapting the devfile-defined command to run in the target component's
    19  // container, modifying it to add environment variables or adapting the path as needed.
    20  func newExecCommand(devfileObj parser.DevfileObj, command v1alpha2.Command) *execCommand {
    21  	return &execCommand{
    22  		command:    command,
    23  		devfileObj: devfileObj,
    24  	}
    25  }
    26  
    27  func (o *execCommand) CheckValidity() error {
    28  	return nil
    29  }
    30  
    31  func (o *execCommand) Execute(ctx context.Context, handler Handler, parentGroup *v1alpha2.CommandGroup) error {
    32  	if o.isTerminating(parentGroup) {
    33  		return handler.ExecuteTerminatingCommand(ctx, o.command)
    34  	}
    35  	return handler.ExecuteNonTerminatingCommand(ctx, o.command)
    36  }
    37  
    38  // isTerminating returns true if not Run or Debug command
    39  func (o *execCommand) isTerminating(parentGroup *v1alpha2.CommandGroup) bool {
    40  	if parentGroup != nil {
    41  		kind := parentGroup.Kind
    42  		return isTerminatingKind(kind)
    43  	}
    44  	if o.command.Exec.Group == nil {
    45  		return true
    46  	}
    47  	kind := o.command.Exec.Group.Kind
    48  	return isTerminatingKind(kind)
    49  }
    50  
    51  func isTerminatingKind(kind v1alpha2.CommandGroupKind) bool {
    52  	return kind != v1alpha2.RunCommandGroupKind && kind != v1alpha2.DebugCommandGroupKind
    53  }
    54  

View as plain text