-
Notifications
You must be signed in to change notification settings - Fork 26
/
importer.go
41 lines (34 loc) · 925 Bytes
/
importer.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
package cmd
import (
"fmt"
"path/filepath"
"github.com/aserto-dev/topaz/pkg/cli/cc"
"github.com/aserto-dev/topaz/pkg/cli/clients"
"github.com/aserto-dev/topaz/pkg/cli/dockerx"
"github.com/fatih/color"
"github.com/google/uuid"
)
type ImportCmd struct {
Directory string `short:"d" required:"" help:"directory containing .json data"`
clients.Config
}
func (cmd *ImportCmd) Run(c *cc.CommonCtx) error {
if running, err := dockerx.IsRunning(dockerx.Topaz); !running || err != nil {
if err != nil {
return err
}
color.Yellow("!!! topaz is not running")
return nil
}
fmt.Fprintf(c.UI.Err(), ">>> importing data...\n")
files, err := filepath.Glob(filepath.Join(cmd.Directory, "*.json"))
if err != nil {
return err
}
cmd.Config.SessionID = uuid.NewString()
dirClient, err := clients.NewDirectoryClient(c, &cmd.Config)
if err != nil {
return err
}
return dirClient.Import(c.Context, files)
}