-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
71 lines (61 loc) · 1.37 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
/**
* @Author: DollarKiller
* @Description: tools cli工具
* @Github: https://github.com/dollarkillerx
* @Date: Create in 20:46 2019-10-05
*/
package main
import (
_ "github.com/dollarkillerx/kvass/config"
"github.com/urfave/cli"
"log"
"os"
"path/filepath"
"runtime"
"strings"
)
/**
命令行参数
-p 指定包名 (如果非go mod 可以默认 系统会自己查询)
*/
func main() {
var opt Option
app := cli.NewApp()
app.Name = "Kvass 微爬虫框架"
app.Email = "dollarkiller@dollarkiller.com"
app.Author = "DollarKiller"
app.Copyright = "https://github.com/dollarkillerx"
app.Version = "v0.0.1"
app.Flags = []cli.Flag{
cli.StringFlag{
Name: "p",
Value: "",
Usage: "指定包名 (如果非go mod 可以默认 系统会自己查询)",
Destination: &opt.PackagePath,
},
}
app.Action = func(c *cli.Context) error {
if opt.PackagePath == "" {
goPath := os.Getenv("GOPATH")
exeFilePath, err := filepath.Abs(os.Args[0])
if err != nil {
log.Fatal(err)
}
if runtime.GOOS == "windows" {
exeFilePath = strings.Replace(exeFilePath, "\\", "/", -1)
}
goPath = goPath + "/src/"
data := strings.Replace(exeFilePath, goPath, "", -1)
opt.PackagePath = data
}
err := clientMag.Run(&opt)
if err != nil {
log.Fatal(err)
}
return nil
}
err := app.Run(os.Args)
if err != nil {
log.Fatal(err)
}
}