Skip to content

Commit ff55b94

Browse files
authored
Add spinner to logs command (#266)
1 parent 4fd1562 commit ff55b94

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

internal/cli/service.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -575,7 +575,14 @@ func (s Service) DownloadLogs(cfg DownloadLogsConfig) error {
575575
return errors.Wrap(err, "unable to fetch log archive request")
576576
}
577577

578+
stopSpinner := spin(
579+
"Downloading logs...",
580+
s.StderrIsTTY,
581+
s.Stderr,
582+
)
583+
578584
logBytes, err := s.APIClient.DownloadLogs(LogDownloadRequest)
585+
stopSpinner()
579586
if err != nil {
580587
return errors.Wrap(err, "unable to download logs")
581588
}

internal/cli/service_logs_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ func TestService_DownloadLogs(t *testing.T) {
7272
require.Error(t, err)
7373
require.Contains(t, err.Error(), "unable to download logs")
7474
require.Contains(t, err.Error(), "download failed")
75+
require.Contains(t, s.mockStderr.String(), "Downloading logs...")
7576
})
7677

7778
t.Run("when writing file fails", func(t *testing.T) {
@@ -97,6 +98,7 @@ func TestService_DownloadLogs(t *testing.T) {
9798

9899
require.Error(t, err)
99100
require.Contains(t, err.Error(), "unable to write log file")
101+
require.Contains(t, s.mockStderr.String(), "Downloading logs...")
100102
})
101103

102104
t.Run("when download succeeds with single log file (no Contents)", func(t *testing.T) {
@@ -138,6 +140,7 @@ func TestService_DownloadLogs(t *testing.T) {
138140
output := s.mockStdout.String()
139141
require.Contains(t, output, "Logs downloaded to")
140142
require.Contains(t, output, "task-123-logs.log")
143+
require.Contains(t, s.mockStderr.String(), "Downloading logs...")
141144
})
142145

143146
t.Run("when download succeeds with zip file (with Contents)", func(t *testing.T) {
@@ -181,6 +184,7 @@ func TestService_DownloadLogs(t *testing.T) {
181184
output := s.mockStdout.String()
182185
require.Contains(t, output, "Logs downloaded to")
183186
require.Contains(t, output, "task-456-logs.zip")
187+
require.Contains(t, s.mockStderr.String(), "Downloading logs...")
184188
})
185189

186190
t.Run("when validation fails", func(t *testing.T) {

0 commit comments

Comments
 (0)