-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
52 lines (45 loc) · 908 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
45
46
47
48
49
50
51
52
package main
import (
"context"
"fmt"
"os"
"github.com/OffchainLabs/unclog/cmd/check"
"github.com/OffchainLabs/unclog/cmd/release"
)
var subcommands = map[string]func(context.Context, []string) error{
"release": release.Run,
"check": check.Run,
}
func errExit(err error) {
fmt.Println(err)
os.Exit(1)
}
func printUsage() {
fmt.Println("Usage: changelog <subcomand> [args]")
fmt.Println("Subcommands:")
for sc := range subcommands {
fmt.Println("\t- ", sc)
}
}
func main() {
if err := dispatch(); err != nil {
errExit(err)
}
}
func dispatch() error {
args := os.Args
if len(args) < 2 {
printUsage()
return fmt.Errorf("no command specified")
}
sub, args := args[1], args[2:]
run := subcommands[sub]
if run == nil {
printUsage()
return fmt.Errorf("invalid subcommand %s", sub)
}
if err := run(context.Background(), args); err != nil {
errExit(err)
}
return nil
}