-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.go
More file actions
81 lines (68 loc) · 1.72 KB
/
Copy pathmain.go
File metadata and controls
81 lines (68 loc) · 1.72 KB
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
package main
import (
"fmt"
"os"
"path"
"github.com/choueric/clog"
"github.com/choueric/regGen/dbg"
"github.com/choueric/regGen/fileflag"
"github.com/choueric/regGen/format"
"github.com/choueric/regGen/licenseload"
"github.com/choueric/regGen/regjar"
)
var (
inputArg string
formatArg string
showVersionArg bool
isFullArg bool
licenseFile string
version = "0.0.4"
BUILD_INFO = ""
)
func joinHomeDir(filepath string) string {
homeDir := os.Getenv("HOME")
if homeDir == "" {
clog.Fatal("$HOME is empty")
}
return path.Join(homeDir, filepath)
}
func init() {
ffPath := joinHomeDir(".regGen/flag")
ff := fileflag.New(ffPath)
ff.FlagSet().BoolVar(&dbg.True, "d", false, "enable debug")
ff.FlagSet().BoolVar(&showVersionArg, "v", false, "show version.")
ff.FlagSet().StringVar(&inputArg, "i", "input.regs", "input file.")
ff.FlagSet().StringVar(&formatArg, "f", "cmacro", "output format type.")
ff.FlagSet().StringVar(&licenseFile, "l", "", "specify license file.")
ff.FlagSet().BoolVar(&isFullArg, "full", false, "full format output")
if err := ff.Parse(); err != nil {
clog.Fatal(err)
}
if showVersionArg {
fmt.Println("version:", version, BUILD_INFO)
os.Exit(0)
}
if dbg.True {
clog.SetFlags(clog.Lshortfile | clog.Lcolor)
clog.Println(inputArg)
}
}
func main() {
fmtter, err := format.New(formatArg)
if err != nil {
clog.Fatal(err)
}
license, err := licenseload.Load(licenseFile)
if err != nil {
clog.Fatal(err)
}
jar, err := regjar.New(inputArg)
if err != nil {
clog.Fatal(err)
}
if dbg.True {
fmt.Println("----------------- format output ---------------")
}
fmtter.FormatLicense(os.Stdout, license)
fmtter.FormatRegJar(os.Stdout, jar, isFullArg)
}