-
Notifications
You must be signed in to change notification settings - Fork 162
/
Copy pathoff.go
67 lines (56 loc) · 1.11 KB
/
off.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
65
66
67
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 (
// Off command
Off struct {
flagSet *flag.FlagSet
opts OffOptions
log log.Logger
}
// OffOptions flag set
OffOptions struct {
ShowHelp bool
}
)
// NewOff returns Off command
func NewOff() *Off {
c := &Off{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 *Off) Name() string {
return "off"
}
// Summary returns command summary
func (c *Off) Summary() string {
return "Disable pythonbrew"
}
// Usage shows command usage
func (c *Off) Usage() {
c.flagSet.Usage()
}
// Run runs use command
func (c *Off) Run(args []string) error {
const tag = "off.run"
c.flagSet.Parse(args[1:])
if c.opts.ShowHelp {
c.Usage()
return nil
}
fp, err := os.Create(path.EnvPermanent())
if err != nil {
return errors.Wrap(err, tag)
}
defer fp.Close()
fp.WriteString("")
return nil
}