Skip to content
This repository was archived by the owner on Oct 21, 2024. It is now read-only.

Commit 9adb9e8

Browse files
authored
Added conditions to print for list commands (#43)
1 parent 18233ab commit 9adb9e8

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

cmd/list.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"github.com/actions/gh-actions-cache/service"
99
"github.com/actions/gh-actions-cache/types"
1010
"github.com/spf13/cobra"
11+
ghTerm "github.com/cli/go-gh/pkg/term"
1112
)
1213

1314
func NewCmdList() *cobra.Command {
@@ -41,9 +42,13 @@ func NewCmdList() *cobra.Command {
4142
return types.HandledError{Message: err.Error(), InnerError: err}
4243
}
4344

45+
// This will be used to determine the if output is terminal
46+
terminal := ghTerm.FromEnv()
47+
isTerminalOutput := terminal.IsTerminalOutput()
48+
4449
if f.Branch == "" && f.Key == "" {
4550
totalCacheSize, err := artifactCache.GetCacheUsage()
46-
if err == nil && totalCacheSize > 0 {
51+
if err == nil && totalCacheSize > 0 && isTerminalOutput {
4752
fmt.Printf("Total caches size %s\n\n", internal.FormatCacheSize(totalCacheSize))
4853
}
4954
}
@@ -58,7 +63,9 @@ func NewCmdList() *cobra.Command {
5863
totalCaches := listCacheResponse.TotalCount
5964
caches := listCacheResponse.ActionsCaches
6065
if len(caches) > 0 {
61-
fmt.Printf("Showing %d of %d cache entries in %s/%s\n\n", displayedEntriesCount(len(caches), f.Limit), totalCaches, repo.Owner(), repo.Name())
66+
if isTerminalOutput {
67+
fmt.Printf("Showing %d of %d cache entries in %s/%s\n\n", displayedEntriesCount(len(caches), f.Limit), totalCaches, repo.Owner(), repo.Name())
68+
}
6269
internal.PrettyPrintCacheList(caches)
6370
} else {
6471
fmt.Printf("There are no Actions caches currently present in this repo or for the provided filters\n")

0 commit comments

Comments
 (0)