-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
68 lines (57 loc) · 1.56 KB
/
main.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
package main
import (
"errors"
"fmt"
"os"
"github.com/chathula/bvm/command"
"github.com/fatih/color"
"github.com/urfave/cli/v2"
)
func test(str string) string {
return color.GreenString(str)
}
func main() {
cliApp := cli.NewApp()
cliApp.Name = "bvm"
cliApp.Description = "🚀 Bun Version Manager - Manage multiple bun versions easily"
cliApp.Usage = cliApp.Name + " <COMMAND>"
cliApp.EnableBashCompletion = true
cliApp.Commands = []*cli.Command{
{
Name: "list-remote",
Aliases: []string{"ls-remote"},
Usage: "List all remote bun versions",
Action: func(c *cli.Context) error {
return command.ListRemote()
},
},
{
Name: "install",
Usage: "Install given bun version",
ArgsUsage: "<version>",
Aliases: []string{"i"},
Action: func(c *cli.Context) error {
if c.Args().Len() == 0 {
return errors.New(fmt.Sprintf("require argument <%s>", color.YellowString("version")))
}
return command.Install(c.Args().First())
},
},
}
cli.AppHelpTemplate = color.YellowString(cliApp.Name) + ` - {{.Description}}
` + color.YellowString("USAGE:") + `
{{.Usage}}
` + color.YellowString("COMMANDS:") + `
{{range .Commands}}{{if not .HideHelp}} ` + color.GreenString(`{{join .Names ", "}}`) + ` {{"\t"}}{{.Usage}}{{ "\n" }}{{end}}{{end}}{{if .VisibleFlags}}{{end}}
` + color.YellowString("EXAMPLES:") + `
{{.Name}} install latest
{{.Name}} install 0.1.1
{{.Name}} use latest
{{.Name}} use 0.1.1
{{.Name}} ls
{{.Name}} ls-remote
`
if err := cliApp.Run(os.Args); err != nil {
fmt.Println(err.Error())
}
}