remove multistep vendor dep

This commit is contained in:
Matthew Hooker 2018-01-17 19:48:21 -08:00
parent ccbd8b8abf
commit 4c5a7e08b5
No known key found for this signature in database
GPG Key ID: 7B5F933D9CE8C6A1
7 changed files with 0 additions and 407 deletions

View File

@ -1,22 +0,0 @@
Copyright (c) 2013 Mitchell Hashimoto
MIT License
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

View File

@ -1,59 +0,0 @@
# multistep
multistep is a Go library for building up complex actions using discrete,
individual "steps." These steps are strung together and run in sequence
to achieve a more complex goal. The runner handles cleanup, cancelling, etc.
if necessary.
## Basic Example
Make a step to perform some action. The step can access your "state",
which is passed between steps by the runner.
```go
type stepAdd struct{}
func (s *stepAdd) Run(state multistep.StateBag) multistep.StepAction {
// Read our value and assert that it is they type we want
value := state.Get("value").(int)
fmt.Printf("Value is %d\n", value)
// Store some state back
state.Put("value", value + 1)
return multistep.ActionContinue
}
func (s *stepAdd) Cleanup(multistep.StateBag) {
// This is called after all the steps have run or if the runner is
// cancelled so that cleanup can be performed.
}
```
Make a runner and call your array of Steps.
```go
func main() {
// Our "bag of state" that we read the value from
state := new(multistep.BasicStateBag)
state.Put("value", 0)
steps := []multistep.Step{
&stepAdd{},
&stepAdd{},
&stepAdd{},
}
runner := &multistep.BasicRunner{Steps: steps}
// Executes the steps
runner.Run(state)
}
```
This will produce:
```
Value is 0
Value is 1
Value is 2
```

View File

@ -1,102 +0,0 @@
package multistep
import (
"sync"
"sync/atomic"
)
type runState int32
const (
stateIdle runState = iota
stateRunning
stateCancelling
)
// BasicRunner is a Runner that just runs the given slice of steps.
type BasicRunner struct {
// Steps is a slice of steps to run. Once set, this should _not_ be
// modified.
Steps []Step
cancelCh chan struct{}
doneCh chan struct{}
state runState
l sync.Mutex
}
func (b *BasicRunner) Run(state StateBag) {
b.l.Lock()
if b.state != stateIdle {
panic("already running")
}
cancelCh := make(chan struct{})
doneCh := make(chan struct{})
b.cancelCh = cancelCh
b.doneCh = doneCh
b.state = stateRunning
b.l.Unlock()
defer func() {
b.l.Lock()
b.cancelCh = nil
b.doneCh = nil
b.state = stateIdle
close(doneCh)
b.l.Unlock()
}()
// This goroutine listens for cancels and puts the StateCancelled key
// as quickly as possible into the state bag to mark it.
go func() {
select {
case <-cancelCh:
// Flag cancel and wait for finish
state.Put(StateCancelled, true)
<-doneCh
case <-doneCh:
}
}()
for _, step := range b.Steps {
// We also check for cancellation here since we can't be sure
// the goroutine that is running to set it actually ran.
if runState(atomic.LoadInt32((*int32)(&b.state))) == stateCancelling {
state.Put(StateCancelled, true)
break
}
action := step.Run(state)
defer step.Cleanup(state)
if _, ok := state.GetOk(StateCancelled); ok {
break
}
if action == ActionHalt {
state.Put(StateHalted, true)
break
}
}
}
func (b *BasicRunner) Cancel() {
b.l.Lock()
switch b.state {
case stateIdle:
// Not running, so Cancel is... done.
b.l.Unlock()
return
case stateRunning:
// Running, so mark that we cancelled and set the state
close(b.cancelCh)
b.state = stateCancelling
fallthrough
case stateCancelling:
// Already cancelling, so just wait until we're done
ch := b.doneCh
b.l.Unlock()
<-ch
}
}

View File

@ -1,123 +0,0 @@
package multistep
import (
"fmt"
"reflect"
"sync"
)
// DebugLocation is the location where the pause is occuring when debugging
// a step sequence. "DebugLocationAfterRun" is after the run of the named
// step. "DebugLocationBeforeCleanup" is before the cleanup of the named
// step.
type DebugLocation uint
const (
DebugLocationAfterRun DebugLocation = iota
DebugLocationBeforeCleanup
)
// StepWrapper is an interface that wrapped steps can implement to expose their
// inner step names to the debug runner.
type StepWrapper interface {
// InnerStepName should return the human readable name of the wrapped step.
InnerStepName() string
}
// DebugPauseFn is the type signature for the function that is called
// whenever the DebugRunner pauses. It allows the caller time to
// inspect the state of the multi-step sequence at a given step.
type DebugPauseFn func(DebugLocation, string, StateBag)
// DebugRunner is a Runner that runs the given set of steps in order,
// but pauses between each step until it is told to continue.
type DebugRunner struct {
// Steps is the steps to run. These will be run in order.
Steps []Step
// PauseFn is the function that is called whenever the debug runner
// pauses. The debug runner continues when this function returns.
// The function is given the state so that the state can be inspected.
PauseFn DebugPauseFn
l sync.Mutex
runner *BasicRunner
}
func (r *DebugRunner) Run(state StateBag) {
r.l.Lock()
if r.runner != nil {
panic("already running")
}
r.runner = new(BasicRunner)
r.l.Unlock()
pauseFn := r.PauseFn
// If no PauseFn is specified, use the default
if pauseFn == nil {
pauseFn = DebugPauseDefault
}
// Rebuild the steps so that we insert the pause step after each
steps := make([]Step, len(r.Steps)*2)
for i, step := range r.Steps {
steps[i*2] = step
name := ""
if wrapped, ok := step.(StepWrapper); ok {
name = wrapped.InnerStepName()
} else {
name = reflect.Indirect(reflect.ValueOf(step)).Type().Name()
}
steps[(i*2)+1] = &debugStepPause{
name,
pauseFn,
}
}
// Then just use a basic runner to run it
r.runner.Steps = steps
r.runner.Run(state)
}
func (r *DebugRunner) Cancel() {
r.l.Lock()
defer r.l.Unlock()
if r.runner != nil {
r.runner.Cancel()
}
}
// DebugPauseDefault is the default pause function when using the
// DebugRunner if no PauseFn is specified. It outputs some information
// to stderr about the step and waits for keyboard input on stdin before
// continuing.
func DebugPauseDefault(loc DebugLocation, name string, state StateBag) {
var locationString string
switch loc {
case DebugLocationAfterRun:
locationString = "after run of"
case DebugLocationBeforeCleanup:
locationString = "before cleanup of"
}
fmt.Printf("Pausing %s step '%s'. Press any key to continue.\n", locationString, name)
var line string
fmt.Scanln(&line)
}
type debugStepPause struct {
StepName string
PauseFn DebugPauseFn
}
func (s *debugStepPause) Run(state StateBag) StepAction {
s.PauseFn(DebugLocationAfterRun, s.StepName, state)
return ActionContinue
}
func (s *debugStepPause) Cleanup(state StateBag) {
s.PauseFn(DebugLocationBeforeCleanup, s.StepName, state)
}

View File

@ -1,48 +0,0 @@
// multistep is a library for bulding up complex actions using individual,
// discrete steps.
package multistep
// A StepAction determines the next step to take regarding multi-step actions.
type StepAction uint
const (
ActionContinue StepAction = iota
ActionHalt
)
// This is the key set in the state bag when using the basic runner to
// signal that the step sequence was cancelled.
const StateCancelled = "cancelled"
// This is the key set in the state bag when a step halted the sequence.
const StateHalted = "halted"
// Step is a single step that is part of a potentially large sequence
// of other steps, responsible for performing some specific action.
type Step interface {
// Run is called to perform the action. The parameter is a "state bag"
// of untyped things. Please be very careful about type-checking the
// items in this bag.
//
// The return value determines whether multi-step sequences continue
// or should halt.
Run(StateBag) StepAction
// Cleanup is called in reverse order of the steps that have run
// and allow steps to clean up after themselves. Do not assume if this
// ran that the entire multi-step sequence completed successfully. This
// method can be ran in the face of errors and cancellations as well.
//
// The parameter is the same "state bag" as Run, and represents the
// state at the latest possible time prior to calling Cleanup.
Cleanup(StateBag)
}
// Runner is a thing that runs one or more steps.
type Runner interface {
// Run runs the steps with the given initial state.
Run(StateBag)
// Cancel cancels a potentially running stack of steps.
Cancel()
}

View File

@ -1,47 +0,0 @@
package multistep
import (
"sync"
)
// StateBag holds the state that is used by the Runner and Steps. The
// StateBag implementation must be safe for concurrent access.
type StateBag interface {
Get(string) interface{}
GetOk(string) (interface{}, bool)
Put(string, interface{})
}
// BasicStateBag implements StateBag by using a normal map underneath
// protected by a RWMutex.
type BasicStateBag struct {
data map[string]interface{}
l sync.RWMutex
once sync.Once
}
func (b *BasicStateBag) Get(k string) interface{} {
result, _ := b.GetOk(k)
return result
}
func (b *BasicStateBag) GetOk(k string) (interface{}, bool) {
b.l.RLock()
defer b.l.RUnlock()
result, ok := b.data[k]
return result, ok
}
func (b *BasicStateBag) Put(k string, v interface{}) {
b.l.Lock()
defer b.l.Unlock()
// Make sure the map is initialized one time, on write
b.once.Do(func() {
b.data = make(map[string]interface{})
})
// Write the data
b.data[k] = v
}

6
vendor/vendor.json vendored
View File

@ -961,12 +961,6 @@
"path": "github.com/mitchellh/mapstructure",
"revision": "281073eb9eb092240d33ef253c404f1cca550309"
},
{
"checksumSHA1": "5x1RX5m8SCkCRLyLL8wBc0qJpV8=",
"path": "github.com/mitchellh/multistep",
"revision": "391576a156a54cfbb4cf5d5eda40cf6ffa3e3a4d",
"revisionTime": "2017-03-16T18:53:39Z"
},
{
"checksumSHA1": "m2L8ohfZiFRsMW3iynaH/TWgnSY=",
"path": "github.com/mitchellh/panicwrap",