forked from peco/peco
-
Notifications
You must be signed in to change notification settings - Fork 0
/
peco.go
54 lines (46 loc) · 916 Bytes
/
peco.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
package main
import (
"fmt"
"os"
"runtime"
"context"
pdebug "github.com/lestrrat/go-pdebug"
"github.com/peco/peco"
"github.com/peco/peco/internal/util"
)
func main() {
defer func() {
if err := recover(); err != nil {
fmt.Fprintf(os.Stderr, "Error:\n%s", err)
os.Exit(1)
}
}()
os.Exit(_main())
}
func _main() int {
if pdebug.Enabled {
pdebug.DefaultCtx.Writer = os.Stderr
}
if envvar := os.Getenv("GOMAXPROCS"); envvar == "" {
runtime.GOMAXPROCS(runtime.NumCPU())
}
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
cli := peco.New()
if err := cli.Run(ctx); err != nil {
switch {
case util.IsCollectResultsError(err):
cli.PrintResults()
return 0
case util.IsIgnorableError(err):
if st, ok := util.GetExitStatus(err); ok {
return st
}
return 0
default:
fmt.Fprintf(os.Stderr, "Error: %s\n", err)
return 1
}
}
return 0
}