mirror of https://github.com/databricks/cli.git
address some comments
This commit is contained in:
parent
298fed28e5
commit
6cc2571add
|
@ -4,7 +4,6 @@ import (
|
||||||
"github.com/databricks/cli/cmd/root"
|
"github.com/databricks/cli/cmd/root"
|
||||||
"github.com/databricks/cli/libs/cmdio"
|
"github.com/databricks/cli/libs/cmdio"
|
||||||
"github.com/databricks/cli/libs/sync"
|
"github.com/databricks/cli/libs/sync"
|
||||||
"github.com/databricks/databricks-sdk-go"
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
"golang.org/x/sync/errgroup"
|
"golang.org/x/sync/errgroup"
|
||||||
)
|
)
|
||||||
|
@ -21,6 +20,7 @@ var importDirCmd = &cobra.Command{
|
||||||
`,
|
`,
|
||||||
|
|
||||||
Annotations: map[string]string{
|
Annotations: map[string]string{
|
||||||
|
// TODO: use render with template at individual call sites for these events.
|
||||||
"template": cmdio.Heredoc(`
|
"template": cmdio.Heredoc(`
|
||||||
{{if eq .Type "IMPORT_STARTED"}}Import started
|
{{if eq .Type "IMPORT_STARTED"}}Import started
|
||||||
{{else if eq .Type "UPLOAD_COMPLETE"}}Uploaded {{.SourcePath}} -> {{.TargetPath}}
|
{{else if eq .Type "UPLOAD_COMPLETE"}}Uploaded {{.SourcePath}} -> {{.TargetPath}}
|
||||||
|
@ -41,7 +41,7 @@ var importDirCmd = &cobra.Command{
|
||||||
LocalPath: sourcePath,
|
LocalPath: sourcePath,
|
||||||
RemotePath: targetPath,
|
RemotePath: targetPath,
|
||||||
Full: true,
|
Full: true,
|
||||||
WorkspaceClient: databricks.Must(databricks.NewWorkspaceClient()),
|
WorkspaceClient: root.WorkspaceClient(ctx),
|
||||||
|
|
||||||
AllowOverwrites: importDirOverwrite,
|
AllowOverwrites: importDirOverwrite,
|
||||||
PersistSnapshot: false,
|
PersistSnapshot: false,
|
||||||
|
|
|
@ -7,31 +7,38 @@ import (
|
||||||
"github.com/databricks/cli/libs/sync"
|
"github.com/databricks/cli/libs/sync"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// TODO: do not emit target directory in upload complete events.
|
||||||
|
|
||||||
type fileIOEvent struct {
|
type fileIOEvent struct {
|
||||||
SourcePath string `json:"source_path,omitempty"`
|
SourcePath string `json:"source_path,omitempty"`
|
||||||
TargetPath string `json:"target_path,omitempty"`
|
TargetPath string `json:"target_path,omitempty"`
|
||||||
Type string `json:"type"`
|
Type string `json:"type"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const (
|
||||||
|
EventTypeImportStarted = "IMPORT_STARTED"
|
||||||
|
EventTypeImportComplete = "IMPORT_COMPLETE"
|
||||||
|
EventTypeUploadComplete = "UPLOAD_COMPLETE"
|
||||||
|
)
|
||||||
|
|
||||||
func newImportStartedEvent(sourcePath, targetPath string) fileIOEvent {
|
func newImportStartedEvent(sourcePath, targetPath string) fileIOEvent {
|
||||||
return fileIOEvent{
|
return fileIOEvent{
|
||||||
SourcePath: sourcePath,
|
SourcePath: sourcePath,
|
||||||
TargetPath: targetPath,
|
TargetPath: targetPath,
|
||||||
Type: "IMPORT_STARTED",
|
Type: EventTypeImportStarted,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func newImportCompleteEvent(sourcePath, targetPath string) fileIOEvent {
|
func newImportCompleteEvent(sourcePath, targetPath string) fileIOEvent {
|
||||||
return fileIOEvent{
|
return fileIOEvent{
|
||||||
Type: "IMPORT_COMPLETE",
|
Type: EventTypeImportComplete,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func newUploadCompleteEvent(sourcePath, targetPath string) fileIOEvent {
|
func newUploadCompleteEvent(sourcePath string) fileIOEvent {
|
||||||
return fileIOEvent{
|
return fileIOEvent{
|
||||||
SourcePath: sourcePath,
|
SourcePath: sourcePath,
|
||||||
TargetPath: targetPath,
|
Type: EventTypeUploadComplete,
|
||||||
Type: "UPLOAD_COMPLETE",
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -44,25 +51,17 @@ func renderSyncEvents(ctx context.Context, eventChannel <-chan sync.Event, synce
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
if e.String() == "" {
|
||||||
// We parse progress events from the sync to track when file uploads
|
|
||||||
// are complete and emit the corresponding events
|
|
||||||
if e.String() != "" && e.Type() == sync.EventTypeProgress {
|
|
||||||
progressEvent := e.(*sync.EventSyncProgress)
|
|
||||||
if progressEvent.Progress < 1 {
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
// TODO: test this works with windows paths
|
switch v := e.(type) {
|
||||||
// remotePath, err := syncer.RemotePath(progressEvent.Path)
|
case *sync.EventSyncProgress:
|
||||||
// if err != nil {
|
// TODO: only emit this event if the the sync event has progress 1.o0
|
||||||
// return err
|
// File upload has been completed. This renders the event for that
|
||||||
// }
|
// on the console
|
||||||
remotePath := "TODO"
|
return cmdio.Render(ctx, newUploadCompleteEvent(v.Path))
|
||||||
err := cmdio.Render(ctx, newUploadCompleteEvent(progressEvent.Path, remotePath))
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,7 +24,6 @@ const (
|
||||||
|
|
||||||
type Event interface {
|
type Event interface {
|
||||||
fmt.Stringer
|
fmt.Stringer
|
||||||
Type() EventType
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type EventBase struct {
|
type EventBase struct {
|
||||||
|
@ -74,10 +73,6 @@ func (e *EventStart) String() string {
|
||||||
return fmt.Sprintf("Action: %s", e.EventChanges.String())
|
return fmt.Sprintf("Action: %s", e.EventChanges.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *EventStart) Type() EventType {
|
|
||||||
return EventTypeStart
|
|
||||||
}
|
|
||||||
|
|
||||||
func newEventStart(seq int, put []string, delete []string) Event {
|
func newEventStart(seq int, put []string, delete []string) Event {
|
||||||
return &EventStart{
|
return &EventStart{
|
||||||
EventBase: newEventBase(seq, EventTypeStart),
|
EventBase: newEventBase(seq, EventTypeStart),
|
||||||
|
@ -111,10 +106,6 @@ func (e *EventSyncProgress) String() string {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *EventSyncProgress) Type() EventType {
|
|
||||||
return EventTypeProgress
|
|
||||||
}
|
|
||||||
|
|
||||||
func newEventProgress(seq int, action EventAction, path string, progress float32) Event {
|
func newEventProgress(seq int, action EventAction, path string, progress float32) Event {
|
||||||
return &EventSyncProgress{
|
return &EventSyncProgress{
|
||||||
EventBase: newEventBase(seq, EventTypeProgress),
|
EventBase: newEventBase(seq, EventTypeProgress),
|
||||||
|
@ -142,10 +133,6 @@ func (e *EventSyncComplete) String() string {
|
||||||
return "Complete"
|
return "Complete"
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *EventSyncComplete) Type() EventType {
|
|
||||||
return EventTypeComplete
|
|
||||||
}
|
|
||||||
|
|
||||||
func newEventComplete(seq int, put []string, delete []string) Event {
|
func newEventComplete(seq int, put []string, delete []string) Event {
|
||||||
return &EventSyncComplete{
|
return &EventSyncComplete{
|
||||||
EventBase: newEventBase(seq, EventTypeComplete),
|
EventBase: newEventBase(seq, EventTypeComplete),
|
||||||
|
|
Loading…
Reference in New Issue