Skip to content

Commit

Permalink
feat(domains): support v1 delete
Browse files Browse the repository at this point in the history
  • Loading branch information
Integralist committed Jan 21, 2025
1 parent 1f40b92 commit 452c45a
Showing 1 changed file with 57 additions and 0 deletions.
57 changes: 57 additions & 0 deletions pkg/commands/domainv1/delete.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package domainv1

import (
"errors"
"io"

"github.com/fastly/go-fastly/v9/fastly"
v1 "github.com/fastly/go-fastly/v9/fastly/domains/v1"

"github.com/fastly/cli/pkg/argparser"
"github.com/fastly/cli/pkg/global"
"github.com/fastly/cli/pkg/text"
)

// DeleteCommand calls the Fastly API to delete domains.
type DeleteCommand struct {
argparser.Base
domainID string
}

// NewDeleteCommand returns a usable command registered under the parent.
func NewDeleteCommand(parent argparser.Registerer, g *global.Data) *DeleteCommand {
c := DeleteCommand{
Base: argparser.Base{
Globals: g,
},
}
c.CmdClause = parent.Command("delete", "Delete a domain").Alias("remove")

// Required.
c.CmdClause.Flag("domain-id", "The Domain Identifier (UUID)").Required().StringVar(&c.domainID)

return &c
}

// Exec invokes the application logic for the command.
func (c *DeleteCommand) Exec(_ io.Reader, out io.Writer) error {
fc, ok := c.Globals.APIClient.(*fastly.Client)
if !ok {
return errors.New("failed to convert interface to a fastly client")
}

input := &v1.DeleteInput{
DomainID: &c.domainID,
}

err := v1.Delete(fc, input)
if err != nil {
c.Globals.ErrLog.AddWithContext(err, map[string]any{
"Domain ID": c.domainID,
})
return err
}

text.Success(out, "Deleted domain (domain-id: %s)", c.domainID)
return nil
}

0 comments on commit 452c45a

Please sign in to comment.