From 9adb9e80c2e39ff9615b50244ef763b8b5d4bcf2 Mon Sep 17 00:00:00 2001 From: Deepak Dahiya <59823596+t-dedah@users.noreply.github.com> Date: Mon, 21 Nov 2022 18:45:26 +0530 Subject: [PATCH] Added conditions to print for list commands (#43) --- cmd/list.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/cmd/list.go b/cmd/list.go index 1deac94..98a96b6 100644 --- a/cmd/list.go +++ b/cmd/list.go @@ -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 { @@ -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)) } } @@ -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")