-
Notifications
You must be signed in to change notification settings - Fork 4
/
delete_pipeline_log.go
47 lines (38 loc) · 1.03 KB
/
delete_pipeline_log.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
package pipeline
import (
"fmt"
"strings"
"github.com/spf13/cobra"
cfg "github.com/calyptia/cli/config"
)
func NewCmdDeletePipelineLog(config *cfg.Config) *cobra.Command {
var confirmed bool
cmd := &cobra.Command{
Use: "pipeline_log PIPELINE_LOGS_ID",
Short: "Delete a specific pipeline log",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
pipelineLogID := args[0]
if !confirmed {
cmd.Printf("Are you sure you want to delete %q? (y/N) ", pipelineLogID)
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.DeletePipelineLog(config.Ctx, pipelineLogID)
return err
},
}
fs := cmd.Flags()
fs.BoolVarP(&confirmed, "yes", "y", false, "Confirm deletion")
return cmd
}