-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
79 lines (73 loc) · 1.62 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
78
79
package main
import (
_ "embed"
"errors"
"flag"
"fmt"
"os"
)
const (
CliName = "rvmbuilder"
Version = "0.2.0"
)
const UTF8BOM = "\xef\xbb\xbf"
//go:embed sample.json
var SampleJson string
func main() {
flag.Usage = func() {
fmt.Fprintf(os.Stderr, "%s outputs a macro to export Aveva Review files and the Navisworks file from the json format options.\n", CliName)
fmt.Fprint(os.Stderr, "\n")
fmt.Fprintf(os.Stderr, "Usage: %s [-o file] {-s | json_file}\n", CliName)
fmt.Fprintf(os.Stderr, "Example: %s sample.json > export.mac\n", CliName)
fmt.Fprint(os.Stderr, "\n")
fmt.Fprint(os.Stderr, "Options:\n")
flag.PrintDefaults()
fmt.Fprint(os.Stderr, "\n")
fmt.Fprint(os.Stderr, "When json_file is -, read standard input instead of a file.\n")
}
vflg := flag.Bool("v", false, "Display version")
sflg := flag.Bool("s", false, "Output a sample JSON")
oflg := flag.String("o", "", "Output file")
flag.Parse()
if *vflg {
fmt.Fprintf(os.Stderr, "%s version %s\n", CliName, Version)
return
}
out := os.Stdout
if *oflg != "" {
var err error
out, err = os.Create(*oflg)
chkErr(err)
}
if *sflg {
fmt.Fprintln(out, SampleJson)
return
}
if flag.NArg() == 0 {
flag.Usage()
return
}
if flag.NArg() >= 2 {
chkErr(errors.New("too many arguments"))
}
var f *os.File
if flag.Arg(0) == "-" {
f = os.Stdin
} else {
var err error
f, err = os.Open(flag.Arg(0))
chkErr(err)
defer f.Close()
}
rb, err := LoadRvmBuilder(f)
chkErr(err)
s, err := MakePml(rb)
chkErr(err)
fmt.Fprint(out, UTF8BOM+s)
}
func chkErr(err error) {
if err != nil {
fmt.Fprintln(os.Stderr, "Error:", err)
os.Exit(1)
}
}