Skip to content

Commit

Permalink
Added conditions to print for list commands (#43)
Browse files Browse the repository at this point in the history
  • Loading branch information
t-dedah committed Nov 21, 2022
1 parent 18233ab commit 9adb9e8
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions cmd/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/actions/gh-actions-cache/service"
"github.com/actions/gh-actions-cache/types"
"github.com/spf13/cobra"
ghTerm "github.com/cli/go-gh/pkg/term"
)

func NewCmdList() *cobra.Command {
Expand Down Expand Up @@ -41,9 +42,13 @@ func NewCmdList() *cobra.Command {
return types.HandledError{Message: err.Error(), InnerError: err}
}

// This will be used to determine the if output is terminal
terminal := ghTerm.FromEnv()
isTerminalOutput := terminal.IsTerminalOutput()

if f.Branch == "" && f.Key == "" {
totalCacheSize, err := artifactCache.GetCacheUsage()
if err == nil && totalCacheSize > 0 {
if err == nil && totalCacheSize > 0 && isTerminalOutput {
fmt.Printf("Total caches size %s\n\n", internal.FormatCacheSize(totalCacheSize))
}
}
Expand All @@ -58,7 +63,9 @@ func NewCmdList() *cobra.Command {
totalCaches := listCacheResponse.TotalCount
caches := listCacheResponse.ActionsCaches
if len(caches) > 0 {
fmt.Printf("Showing %d of %d cache entries in %s/%s\n\n", displayedEntriesCount(len(caches), f.Limit), totalCaches, repo.Owner(), repo.Name())
if isTerminalOutput {
fmt.Printf("Showing %d of %d cache entries in %s/%s\n\n", displayedEntriesCount(len(caches), f.Limit), totalCaches, repo.Owner(), repo.Name())
}
internal.PrettyPrintCacheList(caches)
} else {
fmt.Printf("There are no Actions caches currently present in this repo or for the provided filters\n")
Expand Down

0 comments on commit 9adb9e8

Please sign in to comment.