-
Notifications
You must be signed in to change notification settings - Fork 1
/
delete.go
82 lines (62 loc) · 1.86 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
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
// SPDX-License-Identifier: Apache-2.0
// nolint: dupl // ignore code similarity to keep consistent structure
package main
import (
"errors"
"fmt"
"os/exec"
"github.com/sirupsen/logrus"
)
const deleteAction = "delete"
var (
// ErrorNoDeleteTag is returned when the plugin is missing the delete tag.
ErrorNoDeleteTag = errors.New("no delete tag provided")
)
// Delete represents the plugin configuration for Delete config information.
type Delete struct {
// tag name to delete a release from
Tag string
// Skip the confirmation prompt
Yes bool
}
// Command formats and outputs the Delete command from
// the provided configuration to delete resources.
func (d *Delete) Command() *exec.Cmd {
logrus.Trace("creating gh delete command from plugin configuration")
// variable to store flags for command
var flags []string
// add flag for release command
flags = append(flags, releaseCmd)
// add flag for delete command
flags = append(flags, deleteAction)
// check if delete tag is provided
if len(d.Tag) > 0 {
// add flag for tag from provided delete tag
flags = append(flags, d.Tag)
}
// add flag for delete from provided delete
flags = append(flags, fmt.Sprintf("--yes=%t", d.Yes))
return exec.Command(_gh, flags...)
}
// Exec formats and runs the commands for applying
// the provided configuration to the resources.
func (d *Delete) Exec() error {
logrus.Debug("running delete with provided configuration")
// delete command for the target branch
cmd := d.Command()
// run the delete command for the target branch
err := execCmd(cmd, nil)
if err != nil {
return err
}
return nil
}
// Validate verifies the Delete is properly configured.
func (d *Delete) Validate() error {
logrus.Trace("validating delete configuration")
// verify delete tag is provided if no tag provided error
if len(d.Tag) == 0 {
return ErrorNoDeleteTag
}
return nil
}