-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
44 lines (35 loc) · 827 Bytes
/
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
package main
import (
"fmt"
"os"
"github.com/webercoder/gocean/command"
"github.com/webercoder/gocean/command/coops"
)
func usage(handlers map[string]command.Handler, err ...string) {
if len(err) > 0 {
fmt.Printf("The following errors occurred: %v\n", err)
}
for key := range handlers {
fmt.Printf(" %v\n", key)
}
os.Exit(1)
}
func main() {
handlers := map[string]command.Handler{
"stations": command.NewStationsCommandHandler(),
"coops": coops.NewCompositeCommandHandler(),
}
if len(os.Args) < 2 {
usage(handlers, "Please provide a subcommand")
}
command := os.Args[1]
handler, ok := handlers[command]
if !ok {
usage(handlers, fmt.Sprintf("Command %s is not a valid top-level command", command))
}
err := handler.HandleCommand()
if err != nil {
fmt.Println(err)
os.Exit(1)
}
}