This repository was archived by the owner on Apr 28, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathremove.go
More file actions
61 lines (49 loc) · 1.33 KB
/
remove.go
File metadata and controls
61 lines (49 loc) · 1.33 KB
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
package main
import (
"fmt"
"os"
"path"
"github.com/mitchellh/cli"
"github.com/simplyserenity/kitkit/config"
"github.com/simplyserenity/kitkit/utilities"
)
// RemoveCommands removes a binary from the list
// of binaries that are tracked by kikit
type RemoveCommand struct {
Ui cli.Ui
}
func (c *RemoveCommand) Run(args []string) int {
if len(args) < 2 {
c.Ui.Error(c.Help())
return 1
}
binaryName := args[0]
binaryTag := args[1]
binaries, err := utilities.GetBinaries()
if err != nil {
c.Ui.Error(fmt.Sprintf("failed to get binaries: %s", err))
return 127
}
for _, binary := range binaries {
name, tag := utilities.SplitTrackedName(binary.Name())
if name == binaryName && tag == binaryTag {
if err := os.Remove(path.Join(config.BinariesPath(), binary.Name())); err != nil {
c.Ui.Error(fmt.Sprintf("failed to delete binary: %s", err))
}
c.Ui.Output(fmt.Sprintf("Removed %s %s", name, tag))
return 0
}
}
c.Ui.Error("The specified binary was not found")
return 1
}
func (c *RemoveCommand) Help() string {
return `
Usage: kitkit remove [binary-name] [binary-tag]
Removes the binary that matches the specified tag and name.
This means the binary will be deleted from the binaries folder.
`
}
func (c *RemoveCommand) Synopsis() string {
return "Removes a binary from the the list of tracked binaries"
}