github.com/prasannakumarik25/packer@v1.3.2/helper/multistep/multistep.go (about) 1 // multistep is a library for building up complex actions using individual, 2 // discrete steps. 3 package multistep 4 5 import "context" 6 7 // A StepAction determines the next step to take regarding multi-step actions. 8 type StepAction uint 9 10 const ( 11 ActionContinue StepAction = iota 12 ActionHalt 13 ) 14 15 // This is the key set in the state bag when using the basic runner to 16 // signal that the step sequence was cancelled. 17 const StateCancelled = "cancelled" 18 19 // This is the key set in the state bag when a step halted the sequence. 20 const StateHalted = "halted" 21 22 // Step is a single step that is part of a potentially large sequence 23 // of other steps, responsible for performing some specific action. 24 type Step interface { 25 // Run is called to perform the action. The passed through context will be 26 // cancelled when the runner is cancelled. The second parameter is a "state 27 // bag" of untyped things. Please be very careful about type-checking the 28 // items in this bag. 29 // 30 // The return value determines whether multi-step sequences continue 31 // or should halt. 32 Run(context.Context, StateBag) StepAction 33 34 // Cleanup is called in reverse order of the steps that have run 35 // and allow steps to clean up after themselves. Do not assume if this 36 // ran that the entire multi-step sequence completed successfully. This 37 // method can be ran in the face of errors and cancellations as well. 38 // 39 // The parameter is the same "state bag" as Run, and represents the 40 // state at the latest possible time prior to calling Cleanup. 41 Cleanup(StateBag) 42 } 43 44 // Runner is a thing that runs one or more steps. 45 type Runner interface { 46 // Run runs the steps with the given initial state. 47 Run(StateBag) 48 49 // Cancel cancels a potentially running stack of steps. 50 Cancel() 51 }