-
Notifications
You must be signed in to change notification settings - Fork 26
/
exporter.go
38 lines (30 loc) · 1015 Bytes
/
exporter.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
package cmd
import (
"path/filepath"
"github.com/aserto-dev/topaz/pkg/cli/cc"
"github.com/aserto-dev/topaz/pkg/cli/clients"
"github.com/fatih/color"
"github.com/google/uuid"
)
type ExportCmd struct {
Directory string `short:"d" required:"" help:"directory to write .json data"`
Format FormatVersion `flag:"" short:"f" enum:"3,2" name:"format" default:"3" help:"format of json data"`
clients.Config
}
func (cmd *ExportCmd) Run(c *cc.CommonCtx) error {
if err := CheckRunning(c); err != nil {
return err
}
color.Green(">>> exporting data to %s", cmd.Directory)
objectsFile := filepath.Join(cmd.Directory, "objects.json")
relationsFile := filepath.Join(cmd.Directory, "relations.json")
cmd.Config.SessionID = uuid.NewString()
dirClient, err := clients.NewDirectoryClient(c, &cmd.Config)
if err != nil {
return err
}
if cmd.Format == V2 {
return dirClient.V2.Export(c.Context, objectsFile, relationsFile)
}
return dirClient.V3.Export(c.Context, objectsFile, relationsFile)
}