/
unlink.go
61 lines (52 loc) · 1.28 KB
/
unlink.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
package cmd
import (
"errors"
"fmt"
"io"
"github.com/ironman-project/ironman/pkg/ironman"
"github.com/spf13/cobra"
)
type unlinkCmd struct {
out io.Writer
client *ironman.Ironman
templateID string
}
func newUnlinkCmd(client *ironman.Ironman, out io.Writer) *cobra.Command {
unlink := &unlinkCmd{
out: out,
client: client,
}
// unlinkCmd represents the unlink command
var unlinkCmd = &cobra.Command{
Use: "unlink <template_ID>",
Args: func(cmd *cobra.Command, args []string) error {
if len(args) < 1 {
return errors.New("Template ID is required")
}
if len(args) > 1 {
return errors.New("Invalid number of arguments")
}
return nil
},
Short: "Removes a symlink from the ironman repository",
Long: `Removes a symlink from the ironman repository
Example:
ironman unlink my-template-id
`,
RunE: func(cmd *cobra.Command, args []string) error {
unlink.templateID = args[0]
unlink.client, unlink.out = ensureIronmanClientAndOutput(unlink.client, unlink.out)
return unlink.run()
},
}
return unlinkCmd
}
func (u *unlinkCmd) run() error {
err := u.client.Unlink(u.templateID)
fmt.Fprintf(u.out, "Unlinking template from repository with ID %s...", u.templateID)
if err != nil {
return err
}
fmt.Fprintln(u.out, "Done")
return nil
}