-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
77 lines (69 loc) · 1.18 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
package main
import (
_ "embed"
"log"
"os"
"github.com/urfave/cli/v2"
)
//go:embed VERSION
var VERSION string
//go:generate go run data/data.go
func main() {
app := &cli.App{
Name: "tinytexonfly",
Version: VERSION,
Usage: "Auto install LaTeX packages for TinyTex",
Authors: []*cli.Author{
{
Name: "batkiz",
Email: "[email protected]",
},
},
Action: func(c *cli.Context) error {
file := c.Args().Get(0)
var (
s string
)
if file == "" {
s = ReadPath(".")
execute(s)
return nil
}
fi, err := os.Stat(file)
if err != nil {
log.Fatal(err)
}
if fi.IsDir() {
s = ReadPath(file)
execute(s)
return nil
} else {
s = ReadFile(file)
execute(s)
return nil
}
},
Commands: []*cli.Command{
{
Name: "search",
Aliases: []string{"s"},
Usage: "search file globally through the database",
Action: func(c *cli.Context) error {
file := c.Args().Get(0)
Search(file)
return nil
},
},
},
}
err := app.Run(os.Args)
if err != nil {
log.Fatal(err)
}
}
func execute(s string) {
err := ExecTlmgrInstall(getPackagesNeedInstall(s))
if err != nil {
log.Fatal(err)
}
}