-
Notifications
You must be signed in to change notification settings - Fork 6
/
delete.go
57 lines (46 loc) · 1.53 KB
/
delete.go
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
package databaseindex
import (
"fmt"
"github.com/UpCloudLtd/upcloud-cli/v2/internal/commands"
"github.com/UpCloudLtd/upcloud-cli/v2/internal/completion"
"github.com/UpCloudLtd/upcloud-cli/v2/internal/output"
"github.com/UpCloudLtd/upcloud-cli/v2/internal/resolver"
"github.com/UpCloudLtd/upcloud-go-api/v6/upcloud/request"
"github.com/spf13/pflag"
)
type deleteCommand struct {
*commands.BaseCommand
name string
completion.Database
resolver.CachingDatabase
}
// DeleteCommand creates the "database index delete" command
func DeleteCommand() commands.Command {
return &deleteCommand{
BaseCommand: commands.New(
"delete",
"Delete an index from the specified database.",
"upctl database index delete 55199a44-4751-4e27-9394-7c7661910be3 --name .index-to-delete",
),
}
}
// InitCommand implements Command.InitCommand
func (s *deleteCommand) InitCommand() {
flagSet := &pflag.FlagSet{}
flagSet.StringVar(&s.name, "name", "", "Index name")
s.AddFlags(flagSet)
_ = s.Cobra().MarkFlagRequired("name")
}
// Execute implements commands.MultipleArgumentCommand
func (s *deleteCommand) Execute(exec commands.Executor, arg string) (output.Output, error) {
msg := fmt.Sprintf("Deleting index %s from Managed Database %v", s.name, arg)
exec.PushProgressStarted(msg)
err := exec.All().DeleteManagedDatabaseIndex(exec.Context(), &request.DeleteManagedDatabaseIndexRequest{
ServiceUUID: arg, IndexName: s.name,
})
if err != nil {
return commands.HandleError(exec, msg, err)
}
exec.PushProgressSuccess(msg)
return output.None{}, nil
}