-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
70 lines (62 loc) · 1.25 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
package main
import (
"github.com/fatih/color"
"github.com/litianqi1996/tldr/cmd"
"github.com/urfave/cli/v2"
"os"
)
const VERSION = "0.5"
func main() {
app := cli.NewApp()
app.Version = VERSION
app.Name = "TLDR"
app.Usage = "Too Long; Didn't Read"
app.HideVersion = true
app.HideHelpCommand = true
app.UsageText = "tldr [command]"
app.Flags = []cli.Flag{
&cli.BoolFlag{
Name: "update",
Aliases: []string{"u"},
Usage: "update tldr pages from gitrepo",
Required: false,
},
&cli.BoolFlag{
Name: "clean",
Aliases: []string{"c"},
Usage: "clean tldr repo",
Required: false,
},
}
// do not return err for https://github.com/urfave/cli/issues/707
app.Before = func(c *cli.Context) error {
err := cmd.StartUp()
if err != nil {
ErrShow(err)
_ = cli.ShowAppHelp(c)
}
return nil
}
app.Action = func(c *cli.Context) error {
if c.Bool("update") {
return cmd.UpdateRepo()
}
if c.Bool("clean") {
return cmd.CleanRepo()
}
if c.NArg() > 0 {
err := cmd.Getpage(c.Args().Get(0))
if err != nil {
return err
}
} else {
_ = cli.ShowAppHelp(c)
}
return nil
}
err := app.Run(os.Args)
if err != nil {
ErrShow(err)
}
}
var ErrShow = color.New(color.FgRed).PrintlnFunc()