forked from sachaos/viddy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
92 lines (72 loc) · 2.08 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
package main
import (
"fmt"
"os"
"github.com/adrg/xdg"
"github.com/fatih/color"
"github.com/mattn/go-runewidth"
"github.com/rivo/tview"
"github.com/spf13/viper"
"github.com/tcnksm/go-latest"
)
var version string
var githubTag = &latest.GithubTag{
Owner: "sachaos",
Repository: "viddy",
FixVersionStrFunc: latest.DeleteFrontV(),
}
func printVersion() {
fmt.Printf("viddy version: %s\n", version)
res, err := latest.Check(githubTag, version)
if err == nil && res.Outdated {
text := color.YellowString(fmt.Sprintf("%s is not latest, you should upgrade to v%s", version, res.Current))
fmt.Fprintln(os.Stderr, text)
}
os.Exit(0)
}
func main() {
runewidth.DefaultCondition.EastAsianWidth = false
v := viper.New()
v.SetConfigType("toml")
v.SetConfigName("viddy")
v.AddConfigPath(xdg.ConfigHome)
_ = v.ReadInConfig()
conf, err := newConfig(v, os.Args[1:])
if conf.runtime.help {
help()
os.Exit(0)
}
if conf.runtime.version {
printVersion()
}
if err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
tview.Styles = conf.theme.Theme
app := NewViddy(conf)
if err := app.Run(); err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
}
func help() {
fmt.Println(`
Viddy well, gopher. Viddy well.
Usage:
viddy [options] command
Options:
-b, --bell ring terminal bell changes between updates
-d, --differences highlight changes between updates
-n, --interval <interval> seconds to wait between updates (default "2s")
-p, --precise attempt run command in precise intervals
-c, --clockwork run command in precise intervals forcibly
-t, --no-title turn off header
--shell shell (default "sh")
--shell-options additional shell options
--unfold unfold command result
--pty run on pty (experimental, not for Windows)
--max-history max history length, 0 is infinite (experimental, default "1000")
-h, --help display this help and exit
-v, --version output version information and exit`)
}