-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
73 lines (57 loc) · 1.35 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
package main
import (
"flag"
"fmt"
"log"
"os"
"strings"
)
var Version = "(devel)"
const usage = `Usage:
vanity-imports [option]
Options:
--init creates a sample .vanity-imports.toml config file
-c, --config CONFIG path to the config. Defaults to .vanity-imports.toml
-V, --version print version
`
func main() {
log.SetFlags(0)
flag.Usage = func() { fmt.Fprint(os.Stderr, usage) }
var (
configFlag string = defaultConfigName
versionFlag bool
initFlag bool
)
flag.StringVar(&configFlag, "c", configFlag, "path to the config")
flag.StringVar(&configFlag, "config", configFlag, "path to the config")
flag.BoolVar(&initFlag, "init", initFlag, "creates a sample .vanity-imports.toml config file")
flag.BoolVar(&versionFlag, "version", versionFlag, "print the version")
flag.BoolVar(&versionFlag, "V", versionFlag, "print the version")
flag.Parse()
if versionFlag {
log.Println(Version)
return
}
if initFlag {
err := initSampleConfig()
if err != nil {
log.Fatal(err)
}
return
}
if len(os.Args) > 1 {
log.Fatalf("unknown argument(s): %s", strings.Join(os.Args[1:], " "))
}
config, err := newConfig(configFlag)
if err != nil {
log.Fatal(err)
}
err = build(config)
if err != nil {
log.Fatal(err)
}
err = buildIndex(config)
if err != nil {
log.Fatal(err)
}
}