-
Notifications
You must be signed in to change notification settings - Fork 162
/
Copy pathcleanup.go
63 lines (53 loc) · 1.13 KB
/
cleanup.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
package subcmd
import (
"flag"
"os"
"github.com/pkg/errors"
"github.com/utahta/pythonbrew/flagset"
"github.com/utahta/pythonbrew/log"
"github.com/utahta/pythonbrew/path"
)
type (
// Cleanup command
Cleanup struct {
flagSet *flag.FlagSet
opts CleanupOptions
log log.Logger
}
// CleanupOptions flag set
CleanupOptions struct {
ShowHelp bool
}
)
// NewCleanup returns Cleanup command
func NewCleanup() *Cleanup {
c := &Cleanup{log: log.NewLogger()}
c.flagSet = flagset.New(c.Name(), "[OPTIONS]")
c.flagSet.BoolVar(&c.opts.ShowHelp, "h", false, "Show command usage")
return c
}
// Name returns command name
func (c *Cleanup) Name() string {
return "cleanup"
}
// Summary returns command summary
func (c *Cleanup) Summary() string {
return "Remove all cache"
}
// Usage shows command usage
func (c *Cleanup) Usage() {
c.flagSet.Usage()
}
// Run runs cleanup command
func (c *Cleanup) Run(args []string) error {
const tag = "cleanup.run"
c.flagSet.Parse(args[1:])
if c.opts.ShowHelp {
c.Usage()
return nil
}
if err := os.RemoveAll(path.CacheDir()); err != nil {
return errors.Wrap(err, tag)
}
return nil
}