-
-
Notifications
You must be signed in to change notification settings - Fork 9
/
main.go
62 lines (49 loc) · 1.49 KB
/
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
58
59
60
61
62
//go:build !windows
package main
import (
"fmt"
"os"
"github.com/alecthomas/kong"
"github.com/mrmarble/termsvg/cmd/termsvg/export"
"github.com/mrmarble/termsvg/cmd/termsvg/play"
"github.com/mrmarble/termsvg/cmd/termsvg/rec"
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
)
type Context struct {
Debug bool
}
type VersionFlag string
var (
// Populated by goreleaser during build
version = "master"
commit = "?"
date = ""
)
func init() {
zerolog.SetGlobalLevel(zerolog.InfoLevel)
log.Logger = log.Output(zerolog.ConsoleWriter{Out: os.Stderr, PartsExclude: []string{"time"}})
}
func (v VersionFlag) Decode(_ *kong.DecodeContext) error { return nil }
func (v VersionFlag) IsBool() bool { return true }
func (v VersionFlag) BeforeApply(app *kong.Kong) error {
fmt.Printf("termsvg has version %s built from %s on %s\n", version, commit, date)
app.Exit(0)
return nil
}
func main() {
var cli struct {
Debug bool `help:"Enable debug mode."`
Version VersionFlag `name:"version" help:"Print version information and quit"`
Play play.Cmd `cmd:"" help:"Play a recording."`
Rec rec.Cmd `cmd:"" help:"Record a terminal sesion."`
Export export.Cmd `cmd:"" help:"Export asciicast."`
}
ctx := kong.Parse(&cli,
kong.Name("termsvg"),
kong.Description("A cli tool for recording terminal sessions"),
kong.UsageOnError())
// Call the Run() method of the selected parsed command.
err := ctx.Run(&Context{Debug: cli.Debug})
ctx.FatalIfErrorf(err)
}