-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
52 lines (42 loc) · 1008 Bytes
/
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
package main
import (
"flag"
"fmt"
"io/ioutil"
"os"
)
const name string = "j2h"
var version string
func init() {
flag.Usage = func() {
fmt.Fprintf(os.Stderr, "%s is a tool to convert json to hive ddl\n\n", name)
fmt.Fprintf(os.Stderr, "Usage: %s <option>\n", name)
flag.PrintDefaults()
}
}
func main() {
var (
showVersion = flag.Bool("version", false, "Print version information.")
path = flag.String("path", "", "Path of json file.")
)
flag.Parse()
if *showVersion {
fmt.Fprintln(os.Stdout, "Version: ", version)
os.Exit(0)
}
if _, err := os.Stat(*path); os.IsNotExist(err) {
fmt.Fprintf(os.Stderr, "json file is not exsit in %v\n", *path)
os.Exit(1)
}
b, err := ioutil.ReadFile(*path)
if err != nil {
fmt.Fprintf(os.Stderr, "failed to read json file: %v\n", err)
os.Exit(1)
}
ddl, err := ConvertJSONTOHQL(string(b))
if err != nil {
fmt.Fprintf(os.Stderr, "failed to convert json to hql: %v\n", err)
os.Exit(1)
}
fmt.Fprintln(os.Stdout, ddl)
}