databricks-cli/cmd/sync/sync.go

66 lines
1.6 KiB
Go
Raw Normal View History

2022-07-07 18:56:59 +00:00
package sync
import (
"fmt"
"log"
"time"
"github.com/databricks/bricks/cmd/root"
"github.com/databricks/bricks/git"
"github.com/databricks/bricks/project"
"github.com/spf13/cobra"
)
// syncCmd represents the sync command
var syncCmd = &cobra.Command{
Use: "sync",
Short: "run syncs for the project",
PreRunE: project.Configure,
2022-07-07 18:56:59 +00:00
RunE: func(cmd *cobra.Command, args []string) error {
ctx := cmd.Context()
prj := project.Get(ctx)
wsc := prj.WorkspacesClient()
if *remotePath == "" {
me, err := prj.Me()
if err != nil {
return err
}
repositoryName, err := git.RepositoryName()
if err != nil {
return err
}
*remotePath = fmt.Sprintf("/Repos/%s/%s", me.UserName, repositoryName)
}
log.Printf("[INFO] Remote file sync location: %v", *remotePath)
repoExists, err := git.RepoExists(*remotePath, ctx, wsc)
2022-07-07 18:56:59 +00:00
if err != nil {
return err
}
if !repoExists {
return fmt.Errorf("repo not found, please ensure %s exists", *remotePath)
2022-07-07 18:56:59 +00:00
}
root := prj.Root()
syncCallback := getRemoteSyncCallback(ctx, root, *remotePath, wsc)
err = spawnSyncRoutine(ctx, *interval, syncCallback, *remotePath)
return err
2022-07-07 18:56:59 +00:00
},
}
// project files polling interval
var interval *time.Duration
var remotePath *string
var persistSnapshot *bool
2022-07-07 18:56:59 +00:00
func init() {
root.RootCmd.AddCommand(syncCmd)
interval = syncCmd.Flags().Duration("interval", 1*time.Second, "project files polling interval")
remotePath = syncCmd.Flags().String("remote-path", "", "remote path to store repo in. eg: /Repos/me@example.com/test-repo")
persistSnapshot = syncCmd.Flags().Bool("persist-snapshot", true, "whether to store local snapshots of sync state")
2022-07-07 18:56:59 +00:00
}