-
Notifications
You must be signed in to change notification settings - Fork 4
/
delete_endpoint.go
55 lines (44 loc) · 1.25 KB
/
delete_endpoint.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
package endpoint
import (
"fmt"
"strings"
"github.com/spf13/cobra"
"github.com/calyptia/cli/completer"
cfg "github.com/calyptia/cli/config"
)
func NewCmdDeleteEndpoint(config *cfg.Config) *cobra.Command {
var confirmed bool
completer := completer.Completer{Config: config}
cmd := &cobra.Command{
Use: "endpoint ENDPOINT",
Short: "Delete a single endpoint by ID",
Args: cobra.ExactArgs(1),
ValidArgsFunction: completer.CompletePipelines,
RunE: func(cmd *cobra.Command, args []string) error {
portID := args[0]
if !confirmed {
cmd.Printf("Are you sure you want to delete %q? (y/N) ", portID)
var answer string
_, err := fmt.Scanln(&answer)
if err != nil && err.Error() == "unexpected newline" {
err = nil
}
if err != nil {
return fmt.Errorf("could not to read answer: %v", err)
}
answer = strings.TrimSpace(strings.ToLower(answer))
if answer != "y" && answer != "yes" {
return nil
}
}
err := config.Cloud.DeletePipelinePort(config.Ctx, portID)
if err != nil {
return fmt.Errorf("could not delete endpoint: %w", err)
}
return nil
},
}
fs := cmd.Flags()
fs.BoolVarP(&confirmed, "yes", "y", false, "Confirm deletion")
return cmd
}