MCPcopy Create free account
hub / github.com/cli/cli / buildScanTargets

Function buildScanTargets

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

Source from the content-addressed store, hash-verified

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