/
clean.go
43 lines (36 loc) · 899 Bytes
/
clean.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
package cmd
import (
"os"
"github.com/spf13/cobra"
"github.com/uesyn/dotfiles/bootstrapper/pkg/dir"
"github.com/uesyn/dotfiles/bootstrapper/pkg/log"
)
func newCleanCmd() *cobra.Command {
var cmd = &cobra.Command{
Use: "clean",
Aliases: []string{"apps"},
Short: "clean bootstrapper files",
Run: func(cmd *cobra.Command, args []string) {
var err error
l, err := log.Logger()
l.Info("start to clean up")
err = os.RemoveAll(dir.CacheDir())
if err != nil {
l.WithError(err).Error("failed to clean up cache dir")
os.Exit(1)
}
err = os.RemoveAll(dir.DataDir())
if err != nil {
l.WithError(err).Error("failed to clean up install dir")
os.Exit(1)
}
err = os.RemoveAll(dir.LinkDir())
if err != nil {
l.WithError(err).Error("failed to clean up link dir")
os.Exit(1)
}
l.Info("clean up successfuly")
},
}
return cmd
}