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