This repository has been archived by the owner on Feb 11, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tableau.go
82 lines (74 loc) · 2.99 KB
/
tableau.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
80
81
82
package tableau
import (
"os"
"path/filepath"
"github.com/Wenchy/tableau/internal/atom"
"github.com/Wenchy/tableau/internal/confgen"
"github.com/Wenchy/tableau/internal/importer"
"github.com/Wenchy/tableau/internal/protogen"
"github.com/Wenchy/tableau/internal/xlsxgen"
"github.com/Wenchy/tableau/options"
)
// Excel2Conf converts excel files (with tableau header) to different formatted configuration files.
// Supported formats: json, prototext, and protowire.
func Excel2Conf(protoPackage, indir, outdir string, setters ...options.Option) {
opts := options.ParseOptions(setters...)
g := confgen.NewGenerator(protoPackage, indir, outdir, setters...)
atom.InitZap(opts.LogLevel)
atom.Log.Debugf("options inited: %+v, header: %+v, output: %+v", opts, opts.Header, opts.Output)
if err := g.Generate(opts.Workbook, opts.Worksheet); err != nil {
atom.Log.Errorf("generate failed: %+v", err)
os.Exit(-1)
}
}
// Excel2Proto converts excel files (with tableau header) to protoconf files.
func Excel2Proto(protoPackage, goPackage, indir, outdir string, setters ...options.Option) {
opts := options.ParseOptions(setters...)
g := protogen.NewGenerator(protoPackage, goPackage, indir, outdir, setters...)
atom.InitZap(opts.LogLevel)
atom.Log.Debugf("options inited: %+v, header: %+v, output: %+v", opts, opts.Header, opts.Output)
if err := g.Generate(); err != nil {
atom.Log.Errorf("generate failed: %+v", err)
os.Exit(-1)
}
}
// Proto2Excel converts protoconf files to excel files (with tableau header).
func Proto2Excel(protoPackage, indir, outdir string) {
g := xlsxgen.Generator{
ProtoPackage: protoPackage,
InputDir: indir,
OutputDir: outdir,
}
g.Generate()
}
// ParseMeta parses the @TABLEAU sheet in a workboot.
func ParseMeta(indir, relWorkbookPath string) importer.Importer {
parser := confgen.NewSheetParser(protogen.TableauProtoPackage, "")
return importer.New(
filepath.Join(indir, relWorkbookPath),
importer.Parser(parser),
)
}
// XML2Conf converts xml files to different formatted configuration files.
// Supported formats: json, prototext, and protowire.
func XML2Conf(protoPackage, indir, outdir string, setters ...options.Option) {
opts := options.ParseOptions(setters...)
g := confgen.NewGenerator(protoPackage, indir, outdir, setters...)
atom.InitZap(opts.LogLevel)
atom.Log.Debugf("options inited: %+v, header: %+v, output: %+v", opts, opts.Header, opts.Output)
if err := g.Generate(opts.Workbook, opts.Worksheet); err != nil {
atom.Log.Errorf("generate failed: %+v", err)
os.Exit(-1)
}
}
// XML2Proto converts xml files to protoconf files.
func XML2Proto(protoPackage, goPackage, indir, outdir string, setters ...options.Option) {
opts := options.ParseOptions(setters...)
g := protogen.NewGenerator(protoPackage, goPackage, indir, outdir, setters...)
atom.InitZap(opts.LogLevel)
atom.Log.Debugf("options inited: %+v, header: %+v, output: %+v", opts, opts.Header, opts.Output)
if err := g.Generate(); err != nil {
atom.Log.Errorf("generate failed: %+v", err)
os.Exit(-1)
}
}