-
Notifications
You must be signed in to change notification settings - Fork 31
/
unlink.go
64 lines (56 loc) · 1.41 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
62
63
64
package unlink
import (
"fmt"
"github.com/MakeNowJust/heredoc"
msg "github.com/aziontech/azion-cli/messages/unlink"
"github.com/aziontech/azion-cli/pkg/cmdutil"
"github.com/aziontech/azion-cli/utils"
"github.com/spf13/cobra"
)
type UnlinkCmd struct {
ShouldClean func(f *cmdutil.Factory) bool
Clean func(f *cmdutil.Factory, cmd *UnlinkCmd) error
IsDirEmpty func(dirpath string) (bool, error)
CleanDir func(dirpath string) error
F *cmdutil.Factory
}
func NewUnlinkCmd(f *cmdutil.Factory) *UnlinkCmd {
return &UnlinkCmd{
F: f,
ShouldClean: shouldClean,
Clean: clean,
IsDirEmpty: utils.IsDirEmpty,
CleanDir: utils.CleanDirectory,
}
}
func NewCobraCmd(unlink *UnlinkCmd, f *cmdutil.Factory) *cobra.Command {
cobraCmd := &cobra.Command{
Use: msg.Usage,
Short: msg.ShortDescription,
Long: msg.LongDescription,
SilenceUsage: true,
SilenceErrors: true,
Example: heredoc.Doc(`
$ azion unlink
$ azion unlink --help
$ azion unlink --yes
`),
RunE: func(cmd *cobra.Command, args []string) error {
return unlink.run()
},
}
return cobraCmd
}
func NewCmd(f *cmdutil.Factory) *cobra.Command {
return NewCobraCmd(NewUnlinkCmd(f), f)
}
func (cmd *UnlinkCmd) run() error {
if shouldClean(cmd.F) {
err := cmd.Clean(cmd.F, cmd)
if err != nil {
return err
}
fmt.Fprintf(cmd.F.IOStreams.Out, msg.UnlinkSuccess)
}
return nil
}