-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
57 lines (52 loc) · 1.43 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
package main
import (
"context"
"flag"
"fmt"
"os"
"os/signal"
"ariga.io/entviz/internal/entviz"
)
var (
devURL string
globalUniqueID bool
)
func init() {
flag.StringVar(&devURL, "dev-url", "sqlite3://file?mode=memory&cache=shared&_fk=1", "dev database to be used to generate the schema")
flag.BoolVar(&globalUniqueID, "global-unique-id", false, "enable the Global Unique ID feature")
flag.Usage = func() {
fmt.Fprintf(flag.CommandLine.Output(), "Usage of ariga.io/entviz\n")
fmt.Fprintf(flag.CommandLine.Output(), "\tgo run -mod=mod ariga.io/entviz <Ent schema path>\nFlags:\n")
flag.PrintDefaults()
}
}
func main() {
ctx, _ := signal.NotifyContext(context.Background(), os.Interrupt, os.Kill)
flag.Parse()
schemaPath := flag.Arg(0)
if schemaPath == "" {
flag.Usage()
os.Exit(1)
}
parsedDialect, atlasDriverName, err := entviz.ParseDevURL(devURL)
if err != nil {
fmt.Fprintf(os.Stderr, "error: invalid dev-url: %v\n", err)
os.Exit(1)
}
hcl, err := entviz.HCL(ctx, entviz.HCLOptions{
SchemaPath: schemaPath,
Dialect: parsedDialect,
DevURL: devURL,
GlobalUniqueID: globalUniqueID,
})
if err != nil {
fmt.Fprintf(os.Stderr, "error: %v\n", err)
os.Exit(1)
}
link, err := entviz.Share(ctx, hcl, atlasDriverName)
if err != nil {
fmt.Fprintf(os.Stderr, "error: %v\n", err)
os.Exit(1)
}
fmt.Fprintf(os.Stdout, "Here is a public link to your schema visualization\n\t%s\n", link)
}