From be40bdb032217908c13d02b064338eeeb8dcf77b Mon Sep 17 00:00:00 2001 From: Djordje Lukic Date: Fri, 20 Nov 2020 17:49:43 +0100 Subject: [PATCH] Remove useless Done in the progress writer Signed-off-by: Djordje Lukic --- local/compose.go | 17 +++++------------ local/convergence.go | 6 ------ progress/writer.go | 1 - 3 files changed, 5 insertions(+), 19 deletions(-) diff --git a/local/compose.go b/local/compose.go index e31c2450d..0692c4e34 100644 --- a/local/compose.go +++ b/local/compose.go @@ -129,12 +129,15 @@ func toProgressEvent(jm jsonmessage.JSONMessage, w progress.Writer) { if jm.Progress.Total != 0 { percentage := int(float64(jm.Progress.Current)/float64(jm.Progress.Total)*100) / 2 numSpaces := 50 - percentage + status := progress.Working + if jm.Status == "Pull complete" { + status = progress.Done + } w.Event(progress.Event{ ID: jm.ID, Text: jm.Status, - Status: 0, + Status: status, StatusText: fmt.Sprintf("[%s>%s] ", strings.Repeat("=", percentage), strings.Repeat(" ", numSpaces)), - Done: jm.Status == "Pull complete", }) } else { if jm.Error != nil { @@ -143,21 +146,18 @@ func toProgressEvent(jm jsonmessage.JSONMessage, w progress.Writer) { Text: jm.Status, Status: progress.Error, StatusText: jm.Error.Message, - Done: true, }) } else if jm.Status == "Pull complete" || jm.Status == "Already exists" { w.Event(progress.Event{ ID: jm.ID, Text: jm.Status, Status: progress.Done, - Done: true, }) } else { w.Event(progress.Event{ ID: jm.ID, Text: jm.Status, Status: progress.Working, - Done: false, }) } } @@ -183,7 +183,6 @@ func (s *local) Down(ctx context.Context, projectName string) error { ID: getContainerName(container), Text: "Stopping", Status: progress.Working, - Done: false, }) err := s.containerService.Stop(ctx, container.ID, nil) if err != nil { @@ -193,7 +192,6 @@ func (s *local) Down(ctx context.Context, projectName string) error { ID: getContainerName(container), Text: "Removing", Status: progress.Working, - Done: false, }) err = s.containerService.Delete(ctx, container.ID, containers.DeleteRequest{}) if err != nil { @@ -203,7 +201,6 @@ func (s *local) Down(ctx context.Context, projectName string) error { ID: getContainerName(container), Text: "Removed", Status: progress.Done, - Done: true, }) return nil }) @@ -623,7 +620,6 @@ func (s *local) ensureNetwork(ctx context.Context, n types.NetworkConfig) error ID: fmt.Sprintf("Network %q", n.Name), Status: progress.Working, StatusText: "Create", - Done: false, }) if _, err := s.containerService.apiClient.NetworkCreate(ctx, n.Name, createOpts); err != nil { return errors.Wrapf(err, "failed to create network %s", n.Name) @@ -632,7 +628,6 @@ func (s *local) ensureNetwork(ctx context.Context, n types.NetworkConfig) error ID: fmt.Sprintf("Network %q", n.Name), Status: progress.Done, StatusText: "Created", - Done: true, }) return nil } @@ -651,7 +646,6 @@ func (s *local) ensureVolume(ctx context.Context, volume types.VolumeConfig) err ID: fmt.Sprintf("Volume %q", volume.Name), Status: progress.Working, StatusText: "Create", - Done: false, }) // TODO we miss support for driver_opts and labels _, err := s.volumeService.Create(ctx, volume.Name, nil) @@ -659,7 +653,6 @@ func (s *local) ensureVolume(ctx context.Context, volume types.VolumeConfig) err ID: fmt.Sprintf("Volume %q", volume.Name), Status: progress.Done, StatusText: "Created", - Done: true, }) if err != nil { return err diff --git a/local/convergence.go b/local/convergence.go index f17fe4a8e..e44f77968 100644 --- a/local/convergence.go +++ b/local/convergence.go @@ -169,7 +169,6 @@ func (s *local) createContainer(ctx context.Context, project *types.Project, ser ID: fmt.Sprintf("Service %q", service.Name), Status: progress.Working, StatusText: "Create", - Done: false, }) err := s.runContainer(ctx, project, service, name, number, nil) if err != nil { @@ -179,7 +178,6 @@ func (s *local) createContainer(ctx context.Context, project *types.Project, ser ID: fmt.Sprintf("Service %q", service.Name), Status: progress.Done, StatusText: "Created", - Done: true, }) return nil } @@ -190,7 +188,6 @@ func (s *local) recreateContainer(ctx context.Context, project *types.Project, s ID: fmt.Sprintf("Service %q", service.Name), Status: progress.Working, StatusText: "Recreate", - Done: false, }) err := s.containerService.Stop(ctx, container.ID, nil) if err != nil { @@ -218,7 +215,6 @@ func (s *local) recreateContainer(ctx context.Context, project *types.Project, s ID: fmt.Sprintf("Service %q", service.Name), Status: progress.Done, StatusText: "Recreated", - Done: true, }) setDependentLifecycle(project, service.Name, forceRecreate) return nil @@ -243,7 +239,6 @@ func (s *local) restartContainer(ctx context.Context, service types.ServiceConfi ID: fmt.Sprintf("Service %q", service.Name), Status: progress.Working, StatusText: "Restart", - Done: false, }) err := s.containerService.Start(ctx, container.ID) if err != nil { @@ -253,7 +248,6 @@ func (s *local) restartContainer(ctx context.Context, service types.ServiceConfi ID: fmt.Sprintf("Service %q", service.Name), Status: progress.Done, StatusText: "Restarted", - Done: true, }) return nil } diff --git a/progress/writer.go b/progress/writer.go index 3d48f6d39..dd75a18de 100644 --- a/progress/writer.go +++ b/progress/writer.go @@ -45,7 +45,6 @@ type Event struct { Text string Status EventStatus StatusText string - Done bool startTime time.Time endTime time.Time