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

Function newImageAsset

internal/attachments/userasset.go:69–86  ·  view source on GitHub ↗

newImageAsset applies what only holds for an image: the author may write alt text, and the fallback mirrors the web uploader by stripping the extension and replacing the remaining dots with spaces.

(f asset, alt string)

Source from the content-addressed store, hash-verified

67// text, and the fallback mirrors the web uploader by stripping the extension
68// and replacing the remaining dots with spaces.
69func newImageAsset(f asset, alt string) (UserAsset, error) {
70 a := &imageAsset{f}
71 if err := checkMaxSize(a.asset, maxImageBytes, "images"); err != nil {
72 return nil, err
73 }
74
75 if alt == "" {
76 base := filepath.Base(a.path)
77 alt = strings.ReplaceAll(strings.TrimSuffix(base, filepath.Ext(base)), ".", " ")
78 }
79 a.alt = alt
80
81 if err := checkAltStaysInside(a); err != nil {
82 return nil, err
83 }
84
85 return a, nil
86}
87
88func (a *imageAsset) markdown(assetURL string) string {
89 return fmt.Sprintf("![%s](%s)", escapeAlt(a.alt), assetURL)

Callers 1

newAssetFunction · 0.85

Calls 3

checkMaxSizeFunction · 0.85
checkAltStaysInsideFunction · 0.85
BaseMethod · 0.80

Tested by

no test coverage detected