-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
49 lines (38 loc) · 885 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
package main
import (
"context"
"fmt"
"os"
"syscall"
"github.com/oklog/run"
"github.com/go-fn/fn/internal/clioptions/iostreams"
"github.com/go-fn/fn/internal/cmds"
)
var (
version = "dev"
commit = "none"
date = "unknown"
builtBy = "unknown"
)
const binaryName = "fn"
func main() {
fmt.Fprintf(os.Stderr, "%s version: %s %s %s %s", binaryName, version, commit, date, builtBy)
ctx, cancel := context.WithCancel(context.Background())
ioStreams := iostreams.NewStdIOStreams()
rootCmd := cmds.NewRootCmd(ioStreams)
var group run.Group
group.Add(run.SignalHandler(ctx, syscall.SIGINT, syscall.SIGTERM))
group.Add(func() error {
return rootCmd.ExecuteContext(ctx)
}, func(err error) {
cancel()
})
err := group.Run()
if err != nil {
_, err2 := fmt.Fprintf(ioStreams.ErrOut(), "error: %s", err)
if err2 != nil {
panic(err2)
}
os.Exit(1)
}
}