Skip to content

Commit

Permalink
replace common.Undo behaviour with undo package equivalent
Browse files Browse the repository at this point in the history
  • Loading branch information
Integralist committed Jun 3, 2021
1 parent e918282 commit 6576964
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
7 changes: 4 additions & 3 deletions pkg/compute/deploy.go
Expand Up @@ -20,6 +20,7 @@ import (
"github.com/fastly/cli/pkg/config"
"github.com/fastly/cli/pkg/errors"
"github.com/fastly/cli/pkg/text"
"github.com/fastly/cli/pkg/undo"
"github.com/fastly/go-fastly/v3/fastly"
"github.com/kennygrant/sanitize"
)
Expand Down Expand Up @@ -174,7 +175,7 @@ func (c *DeployCommand) Exec(in io.Reader, out io.Writer) (err error) {
progress = text.NewQuietProgress(out)
}

undoStack := common.NewUndoStack()
undoStack := undo.NewStack()

defer func() {
if err != nil {
Expand Down Expand Up @@ -562,7 +563,7 @@ func cfgBackend(backend string, backendPort uint, out io.Writer, in io.Reader, f

// createDomain creates the given domain and handle unrolling the stack in case
// of an error (i.e. will ensure the domain is deleted if there is an error).
func createDomain(progress text.Progress, client api.Interface, serviceID string, version int, domain string, undoStack common.Undoer) error {
func createDomain(progress text.Progress, client api.Interface, serviceID string, version int, domain string, undoStack undo.Stacker) error {
progress.Step("Creating domain...")

undoStack.Push(func() error {
Expand All @@ -587,7 +588,7 @@ func createDomain(progress text.Progress, client api.Interface, serviceID string

// createBackend creates the given domain and handle unrolling the stack in case
// of an error (i.e. will ensure the backend is deleted if there is an error).
func createBackend(progress text.Progress, client api.Interface, serviceID string, version int, backend string, backendPort uint, undoStack common.Undoer) error {
func createBackend(progress text.Progress, client api.Interface, serviceID string, version int, backend string, backendPort uint, undoStack undo.Stacker) error {
progress.Step("Creating backend...")

undoStack.Push(func() error {
Expand Down
2 changes: 2 additions & 0 deletions pkg/undo/doc.go
@@ -0,0 +1,2 @@
// Package undo contains abstractions for working with a stack of state changes.
package undo
2 changes: 1 addition & 1 deletion pkg/undo/undo.go
Expand Up @@ -59,7 +59,7 @@ func (s *Stack) Len() int {
// calling each Fn function state in FIFO order. If any Fn returns an
// error, it gets logged to the provided writer. Should be deferrerd, such as:
//
// undoStack := common.NewStack()
// undoStack := undo.NewStack()
// defer func() { undoStack.RunIfError(w, err) }()
//
func (s *Stack) RunIfError(w io.Writer, err error) {
Expand Down

0 comments on commit 6576964

Please sign in to comment.