github.com/clusterize-io/tusk@v0.6.3-0.20211001020217-cfe8a8cd0d4a/runner/context.go (about)

     1  package runner
     2  
     3  import "github.com/clusterize-io/tusk/ui"
     4  
     5  // Context contains contextual information about a run.
     6  type Context struct {
     7  	// Logger is responsible for logging actions as they occur. It is required to
     8  	// be defined for a Context.
     9  	Logger *ui.Logger
    10  
    11  	// Interpreter specifies how a command is meant to be executed.
    12  	Interpreter []string
    13  
    14  	taskStack []*Task
    15  }
    16  
    17  // PushTask adds a sub-task to the task stack.
    18  func (r *Context) PushTask(t *Task) {
    19  	r.taskStack = append(r.taskStack, t)
    20  }
    21  
    22  // Tasks returns the list of tasks in the stack, in order.
    23  func (r *Context) Tasks() []string {
    24  	output := make([]string, len(r.taskStack))
    25  	for i, t := range r.taskStack {
    26  		output[i] = t.Name
    27  	}
    28  	return output
    29  }