-
Notifications
You must be signed in to change notification settings - Fork 71
Expand file tree
/
Copy pathdelete.go
More file actions
99 lines (87 loc) · 2.91 KB
/
delete.go
File metadata and controls
99 lines (87 loc) · 2.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
package dictionary
import (
"context"
"io"
"github.com/fastly/go-fastly/v12/fastly"
"4d63.com/optional"
"github.com/fastly/cli/pkg/argparser"
"github.com/fastly/cli/pkg/errors"
"github.com/fastly/cli/pkg/global"
"github.com/fastly/cli/pkg/text"
)
// DeleteCommand calls the Fastly API to delete a service.
type DeleteCommand struct {
argparser.Base
Input fastly.DeleteDictionaryInput
serviceName argparser.OptionalServiceNameID
serviceVersion argparser.OptionalServiceVersion
autoClone argparser.OptionalAutoClone
}
// 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 Fastly edge dictionary from a Fastly service version")
// Required.
c.CmdClause.Flag("name", "Name of Dictionary").Short('n').Required().StringVar(&c.Input.Name)
c.RegisterFlag(argparser.StringFlagOpts{
Name: argparser.FlagVersionName,
Description: argparser.FlagVersionDesc,
Dst: &c.serviceVersion.Value,
Required: true,
})
// Optional.
c.RegisterAutoCloneFlag(argparser.AutoCloneFlagOpts{
Action: c.autoClone.Set,
Dst: &c.autoClone.Value,
})
c.RegisterFlag(argparser.StringFlagOpts{
Name: argparser.FlagServiceIDName,
Description: argparser.FlagServiceIDDesc,
Dst: &g.Manifest.Flag.ServiceID,
Short: 's',
})
c.RegisterFlag(argparser.StringFlagOpts{
Action: c.serviceName.Set,
Name: argparser.FlagServiceName,
Description: argparser.FlagServiceNameDesc,
Dst: &c.serviceName.Value,
})
return &c
}
// Exec invokes the application logic for the command.
func (c *DeleteCommand) Exec(_ io.Reader, out io.Writer) error {
serviceID, serviceVersion, err := argparser.ServiceDetails(argparser.ServiceDetailsOpts{
Active: optional.Of(false),
Locked: optional.Of(false),
AutoCloneFlag: c.autoClone,
APIClient: c.Globals.APIClient,
Manifest: *c.Globals.Manifest,
Out: out,
ServiceNameFlag: c.serviceName,
ServiceVersionFlag: c.serviceVersion,
VerboseMode: c.Globals.Flags.Verbose,
})
if err != nil {
c.Globals.ErrLog.AddWithContext(err, map[string]any{
"Service ID": serviceID,
"Service Version": errors.ServiceVersion(serviceVersion),
})
return err
}
c.Input.ServiceID = serviceID
c.Input.ServiceVersion = fastly.ToValue(serviceVersion.Number)
err = c.Globals.APIClient.DeleteDictionary(context.TODO(), &c.Input)
if err != nil {
c.Globals.ErrLog.AddWithContext(err, map[string]any{
"Service ID": serviceID,
"Service Version": fastly.ToValue(serviceVersion.Number),
})
return err
}
text.Success(out, "Deleted dictionary %s (service %s version %d)", c.Input.Name, c.Input.ServiceID, c.Input.ServiceVersion)
return nil
}