-
Notifications
You must be signed in to change notification settings - Fork 1
/
vkg.go
57 lines (45 loc) · 858 Bytes
/
vkg.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
package main
import (
"fmt"
"os"
"github.com/pepegar/vkg/commands"
)
type App struct {
Commands []commands.Command
}
func (a *App) Dispatch(name string) *commands.Command {
for _, c := range a.Commands {
if c.HasName(name) {
return &c
}
}
return nil
}
func main() {
app := App{
Commands: []commands.Command{
commands.SearchCommand,
commands.InstallCommand,
commands.UninstallCommand,
commands.ListCommand,
commands.FreezeCommand,
},
}
var usage = `
Usage: vkg [command]
Commands:
`
for _, command := range app.Commands {
usage += " " + command.Usage + " - " + command.Description + "\r\n"
}
if len(os.Args) > 1 {
command := app.Dispatch(os.Args[1])
if command != nil {
command.Action()
} else {
fmt.Println("command " + os.Args[1] + " does not exist")
}
} else {
fmt.Println(usage)
}
}