MCPcopy Index your code
hub / github.com/cli/cli / buildScanTargets

Function buildScanTargets

pkg/cmd/skills/list/list.go:208–263  ·  view source on GitHub ↗
(opts *ListOptions)

Source from the content-addressed store, hash-verified

206}
207
208func buildScanTargets(opts *ListOptions) ([]scanTarget, error) {
209 if opts.Dir != "" {
210 dir, err := filepath.Abs(opts.Dir)
211 if err != nil {
212 return nil, fmt.Errorf("could not resolve path: %w", err)
213 }
214 if _, err := os.Stat(dir); err != nil {
215 return nil, fmt.Errorf("could not access directory: %w", err)
216 }
217 return []scanTarget{{dir: dir, scope: scopeCustom}}, nil
218 }
219
220 gitRoot := installer.ResolveGitRoot(opts.GitClient)
221 homeDir := installer.ResolveHomeDir()
222
223 agentHosts, err := selectedAgentHosts(opts.Agent)
224 if err != nil {
225 return nil, err
226 }
227 scopes := selectedScopes(opts.Scope)
228
229 byDir := map[string]int{}
230 var targets []scanTarget
231 for _, agentHost := range agentHosts {
232 for _, scope := range scopes {
233 dir, installErr := agentHost.InstallDir(scope, gitRoot, homeDir)
234 if installErr != nil {
235 continue
236 }
237
238 if idx, ok := byDir[dir]; ok {
239 targets[idx].agentHostIDs = appendAgentHostID(targets[idx].agentHostIDs, agentHost.ID)
240 targets[idx].filter = mergeScanFilters(targets[idx].filter, scanFilterForAgentHost(agentHost, scope))
241 continue
242 }
243
244 byDir[dir] = len(targets)
245 targets = append(targets, scanTarget{
246 dir: dir,
247 agentHostIDs: []string{agentHost.ID},
248 scope: string(scope),
249 filter: scanFilterForAgentHost(agentHost, scope),
250 })
251 }
252 }
253 if shouldListPublishedProjectSkills(opts.Agent, scopes, gitRoot) {
254 targets = append(targets, scanTarget{
255 dir: filepath.Join(gitRoot, "skills"),
256 agentHostIDs: []string{agentHostPublished},
257 scope: string(registry.ScopeProject),
258 filter: scanPublishedOnly,
259 })
260 }
261
262 return targets, nil
263}
264
265func selectedAgentHosts(agentID string) ([]*registry.AgentHost, error) {

Callers 1

listInstalledSkillsFunction · 0.85

Calls 11

ResolveGitRootFunction · 0.92
ResolveHomeDirFunction · 0.92
selectedAgentHostsFunction · 0.85
selectedScopesFunction · 0.85
appendAgentHostIDFunction · 0.85
mergeScanFiltersFunction · 0.85
scanFilterForAgentHostFunction · 0.85
InstallDirMethod · 0.80
JoinMethod · 0.80
ErrorfMethod · 0.65

Tested by

no test coverage detected