-
Notifications
You must be signed in to change notification settings - Fork 20
/
dns_delete.go
62 lines (51 loc) · 1.39 KB
/
dns_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
58
59
60
61
62
package cmd
import (
"fmt"
"github.com/spf13/cobra"
"github.com/exoscale/cli/pkg/account"
"github.com/exoscale/cli/pkg/globalstate"
exoapi "github.com/exoscale/egoscale/v2/api"
)
func init() {
dnsDeleteCmd := &cobra.Command{
Use: "delete DOMAIN-NAME|ID",
Short: "Delete a domain",
Aliases: gDeleteAlias,
RunE: func(cmd *cobra.Command, args []string) error {
if len(args) != 1 {
return cmd.Usage()
}
force, err := cmd.Flags().GetBool("force")
if err != nil {
return err
}
return deleteDomain(args[0], force)
},
}
dnsCmd.AddCommand(dnsDeleteCmd)
dnsDeleteCmd.Flags().BoolP("force", "f", false, cmdFlagForceHelp)
}
func deleteDomain(ident string, force bool) error {
domain, err := domainFromIdent(ident)
if err != nil {
return err
}
if !force && !askQuestion(fmt.Sprintf("Are you sure you want to delete %q domain?", *domain.UnicodeName)) {
return nil
}
ctx := exoapi.WithEndpoint(gContext, exoapi.NewReqEndpoint(account.CurrentAccount.Environment, account.CurrentAccount.DefaultZone))
decorateAsyncOperation(fmt.Sprintf("Deleting DNS domain %q...", *domain.UnicodeName), func() {
err = globalstate.EgoscaleClient.DeleteDNSDomain(
ctx,
account.CurrentAccount.DefaultZone,
domain,
)
})
if err != nil {
return err
}
if !globalstate.Quiet {
fmt.Printf("Domain %q was deleted successfully\n", *domain.UnicodeName)
}
return nil
}