-
Notifications
You must be signed in to change notification settings - Fork 2
/
spandex.go
48 lines (44 loc) · 1.03 KB
/
spandex.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
package main
import (
"flag"
"fmt"
"github.com/golang/glog"
"github.com/hazaelsan/spandex/expander"
_ "github.com/hazaelsan/spandex/expander/autokey"
_ "github.com/hazaelsan/spandex/expander/textexpander"
)
// Command line flags.
var (
srcExp = flag.String("source", "", "source expander")
dstExp = flag.String("dest", "", "destination expander")
importName = flag.String("import_name", "", "group name for imported snippets")
)
func main() {
flag.Parse()
if *srcExp == "" || *dstExp == "" {
glog.Exit("-source and -dest must be set")
}
if *importName == "" {
*importName = fmt.Sprintf("Imported from %v", *srcExp)
}
src, err := expander.New(*srcExp)
if err != nil {
glog.Exit(err)
}
if err := src.Load(); err != nil {
glog.Exit(err)
}
dst, err := expander.New(*dstExp)
if err != nil {
glog.Exit(err)
}
root := &expander.Group{Name: *importName}
for _, g := range src.Groups() {
g.Parent = root
}
root.MergeAll(src.Groups())
dst.SetGroup(root)
if err := dst.Write(); err != nil {
glog.Exit(err)
}
}