MCPcopy
hub / github.com/cli/cli / listRun

Function listRun

pkg/cmd/secret/list/list.go:106–220  ·  view source on GitHub ↗
(opts *ListOptions)

Source from the content-addressed store, hash-verified

104}
105
106func listRun(opts *ListOptions) error {
107 client, err := opts.HttpClient()
108 if err != nil {
109 return fmt.Errorf("could not create http client: %w", err)
110 }
111
112 orgName := opts.OrgName
113 envName := opts.EnvName
114
115 var baseRepo ghrepo.Interface
116 if orgName == "" && !opts.UserSecrets {
117 baseRepo, err = opts.BaseRepo()
118 if err != nil {
119 return err
120 }
121 }
122
123 secretEntity, err := shared.GetSecretEntity(orgName, envName, opts.UserSecrets)
124 if err != nil {
125 return err
126 }
127
128 secretApp, err := shared.GetSecretApp(opts.Application, secretEntity)
129 if err != nil {
130 return err
131 }
132
133 if !shared.IsSupportedSecretEntity(secretApp, secretEntity) {
134 return fmt.Errorf("%s secrets are not supported for %s", secretEntity, secretApp)
135 }
136
137 // Since populating the `NumSelectedRepos` field costs further API requests
138 // (one per secret), it's important to avoid extra calls when the output will
139 // not present the field's value. So, we should only populate this field in
140 // these cases:
141 // 1. The command is run in the TTY mode without the `--json <fields>` option.
142 // 2. The command is run with `--json <fields>` option, and `numSelectedRepos`
143 // is among the selected fields. In this case, TTY mode is irrelevant.
144 showSelectedRepoInfo := opts.IO.IsStdoutTTY()
145 if opts.Exporter != nil {
146 // Note that if there's an exporter set, then we don't mind the TTY mode
147 // because we just have to populate the requested fields.
148 showSelectedRepoInfo = slices.Contains(opts.Exporter.Fields(), fieldNumSelectedRepos)
149 }
150
151 var secrets []Secret
152 switch secretEntity {
153 case shared.Repository:
154 secrets, err = getRepoSecrets(client, baseRepo, secretApp)
155 case shared.Environment:
156 secrets, err = getEnvSecrets(client, baseRepo, envName)
157 case shared.Organization, shared.User:
158 var cfg gh.Config
159 var host string
160
161 cfg, err = opts.Config()
162 if err != nil {
163 return err

Callers 3

Test_listRunFunction · 0.70
NewCmdListFunction · 0.70

Calls 15

AuthenticationMethod · 0.95
GetSecretEntityFunction · 0.92
GetSecretAppFunction · 0.92
IsSupportedSecretEntityFunction · 0.92
NewNoResultsErrorFunction · 0.92
NewFunction · 0.92
WithHeaderFunction · 0.92
getRepoSecretsFunction · 0.85
getEnvSecretsFunction · 0.85
getUserSecretsFunction · 0.85
getOrgSecretsFunction · 0.85
IsStdoutTTYMethod · 0.80

Tested by 2

Test_listRunFunction · 0.56