-
Notifications
You must be signed in to change notification settings - Fork 53
/
Copy pathmain.go
57 lines (44 loc) · 1018 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
53
54
55
56
57
package main
import (
"fmt"
"os"
"path/filepath"
rat "github.com/ericfreese/rat/lib"
flag "github.com/spf13/pflag"
)
var (
// RatVersion is the version of the application
RatVersion = "0.1.0"
)
var flags struct {
cmd string
mode string
version bool
}
func init() {
flag.StringVarP(&flags.cmd, "cmd", "c", "", "command to run")
flag.StringVarP(&flags.mode, "mode", "m", "default", "name of mode")
flag.BoolVarP(&flags.version, "version", "v", false, "display version and exit")
flag.Parse()
}
func main() {
var err error
if flags.version {
fmt.Println(RatVersion)
return
}
if err = rat.Init(); err != nil {
panic(err)
}
defer rat.Close()
if config, err := os.Open(filepath.Join(rat.ConfigDir, "ratrc")); err == nil {
defer config.Close()
rat.LoadConfig(config)
}
if len(flags.cmd) > 0 {
rat.PushPager(rat.NewCmdPager(flags.mode, flags.cmd, rat.Context{}))
} else {
rat.PushPager(rat.NewReadPager(os.Stdin, "<stdin>", flags.mode, rat.Context{}))
}
rat.Run()
}