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

Function nameFromFile

pkg/cmd/issue/artifact/create/create.go:422–430  ·  view source on GitHub ↗

nameFromFile returns the name gh gives an artifact from a file: its base name, as typed rather than a symlink's target, cleaned up to fit the server's rule for names, since the user didn't type it. Names may contain letters, numbers, accent marks, spaces, ".", "-" and "_", and must start and end wit

(path string)

Source from the content-addressed store, hash-verified

420// becomes "draft.md". The result is empty when the file name has no letters
421// or numbers.
422func nameFromFile(path string) string {
423 name := strings.Map(func(r rune) rune {
424 if isLetterOrNumber(r) || unicode.IsMark(r) || strings.ContainsRune(" .-_", r) {
425 return r
426 }
427 return -1
428 }, filepath.Base(path))
429 return strings.TrimFunc(name, func(r rune) bool { return !isLetterOrNumber(r) })
430}
431
432func isLetterOrNumber(r rune) bool {
433 return unicode.IsLetter(r) || unicode.IsNumber(r)

Callers 1

readSourceFunction · 0.85

Calls 3

isLetterOrNumberFunction · 0.85
MapMethod · 0.80
BaseMethod · 0.80

Tested by

no test coverage detected