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

Function attachmentArgForDestination

internal/attachments/references.go:350–364  ·  view source on GitHub ↗

attachmentArgForDestination is where the two halves of this package meet: it takes a markdown destination and answers which attached file, if any, it names. Only a local path can name one, and markdown offers several spellings for the same path, so each is resolved to an absolute path and looked up

(dest string, byPath map[string]int)

Source from the content-addressed store, hash-verified

348// Only a local path can name one, and markdown offers several spellings for
349// the same path, so each is resolved to an absolute path and looked up.
350func attachmentArgForDestination(dest string, byPath map[string]int) (int, bool) {
351 if dest == "" || strings.HasPrefix(dest, "#") || isRemoteDestination(dest) {
352 return 0, false
353 }
354 for _, path := range candidatePaths(dest) {
355 abs, err := filepath.Abs(path)
356 if err != nil {
357 continue
358 }
359 if i, ok := byPath[abs]; ok {
360 return i, true
361 }
362 }
363 return 0, false
364}
365
366// isRemoteDestination reports whether a destination addresses somewhere other
367// than the filesystem, so that an attached file is never confused with a URI.

Callers 1

scanMarkdownRefsFunction · 0.85

Calls 2

isRemoteDestinationFunction · 0.85
candidatePathsFunction · 0.85

Tested by

no test coverage detected