From d034a69164db3e592d45c9e4c2c1376351de3eab Mon Sep 17 00:00:00 2001 From: "Babak K. Shandiz" Date: Thu, 4 Apr 2024 20:09:28 +0100 Subject: [PATCH] Add comment to explain `showSelectedReposInfo` assignment Signed-off-by: Babak K. Shandiz --- pkg/cmd/secret/list/list.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/pkg/cmd/secret/list/list.go b/pkg/cmd/secret/list/list.go index acf6eba52..0d2e6f3f1 100644 --- a/pkg/cmd/secret/list/list.go +++ b/pkg/cmd/secret/list/list.go @@ -117,6 +117,13 @@ func listRun(opts *ListOptions) error { return fmt.Errorf("%s secrets are not supported for %s", secretEntity, secretApp) } + // Since populating the `NumSelectedRepos` field costs further API requests + // (one per secret), it's important to avoid extra calls when the output will + // not present the field's value. So, we should only populate this field in + // these cases: + // 1. The command is run in the TTY mode without the `--json ` option. + // 2. The command is run with `--json ` option, and `numSelectedRepos` + // is among the selected fields. In this case, TTY mode is irrelevant. showSelectedRepoInfo := opts.IO.IsStdoutTTY() if opts.Exporter != nil { // Note that if there's an exporter set, then we don't mind the TTY mode