github.com/fastly/cli@v1.7.2-0.20240304164155-9d0f1d77c3bf/pkg/commands/serviceauth/delete.go (about) 1 package serviceauth 2 3 import ( 4 "io" 5 6 "github.com/fastly/go-fastly/v9/fastly" 7 8 "github.com/fastly/cli/pkg/argparser" 9 "github.com/fastly/cli/pkg/global" 10 "github.com/fastly/cli/pkg/text" 11 ) 12 13 // DeleteCommand calls the Fastly API to delete service authorizations. 14 type DeleteCommand struct { 15 argparser.Base 16 Input fastly.DeleteServiceAuthorizationInput 17 } 18 19 // NewDeleteCommand returns a usable command registered under the parent. 20 func NewDeleteCommand(parent argparser.Registerer, g *global.Data) *DeleteCommand { 21 c := DeleteCommand{ 22 Base: argparser.Base{ 23 Globals: g, 24 }, 25 } 26 c.CmdClause = parent.Command("delete", "Delete service authorization").Alias("remove") 27 28 // Required. 29 c.CmdClause.Flag("id", "ID of the service authorization to delete").Required().StringVar(&c.Input.ID) 30 return &c 31 } 32 33 // Exec invokes the application logic for the command. 34 func (c *DeleteCommand) Exec(_ io.Reader, out io.Writer) error { 35 if err := c.Globals.APIClient.DeleteServiceAuthorization(&c.Input); err != nil { 36 c.Globals.ErrLog.AddWithContext(err, map[string]any{ 37 "Service Authorization ID": c.Input.ID, 38 }) 39 return err 40 } 41 42 text.Success(out, "Deleted service authorization %s", c.Input.ID) 43 return nil 44 }