-
Notifications
You must be signed in to change notification settings - Fork 162
/
Copy pathinit.go
69 lines (57 loc) · 1.25 KB
/
init.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
68
69
package subcmd
import (
"flag"
"fmt"
"github.com/pkg/errors"
"github.com/utahta/pythonbrew/flagset"
"github.com/utahta/pythonbrew/log"
"github.com/utahta/pythonbrew/path"
"github.com/utahta/pythonbrew/rc"
)
type (
// Init command
Init struct {
flagSet *flag.FlagSet
opts InitOptions
log log.Logger
}
// InitOptions flag set
InitOptions struct {
ShowHelp bool
ShellType string
}
)
// NewInit returns Init command
func NewInit() *Init {
c := &Init{log: log.NewLogger()}
c.flagSet = flagset.New(c.Name(), "[OPTIONS]")
c.flagSet.BoolVar(&c.opts.ShowHelp, "h", false, "Show command usage")
c.flagSet.StringVar(&c.opts.ShellType, "s", "bash", "Type of shell")
return c
}
// Name returns command name
func (c *Init) Name() string {
return "init"
}
// Summary returns command summary
func (c *Init) Summary() string {
return "Please refer to README.md"
}
// Usage shows command usage
func (c *Init) Usage() {
c.flagSet.Usage()
}
// Run runs init command
func (c *Init) Run(args []string) error {
const tag = "init.run"
c.flagSet.Parse(args[1:])
if c.opts.ShowHelp {
c.Usage()
return nil
}
if err := path.MkdirAll(); err != nil {
return errors.Wrap(err, tag)
}
fmt.Print(rc.Shell(rc.ShellType(c.opts.ShellType)))
return nil
}