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