MCPcopy Index your code
hub / github.com/cloudfoundry/cli / Complete

Method Complete

command/flag/path.go:150–175  ·  view source on GitHub ↗
(prefix string)

Source from the content-addressed store, hash-verified

148type PathWithAt string
149
150func (PathWithAt) Complete(prefix string) []flags.Completion {
151 if prefix == "" || prefix[0] != '@' {
152 return nil
153 }
154
155 prefix = prefix[1:]
156
157 var homeDir string
158 if strings.HasPrefix(prefix, fmt.Sprintf("~%c", os.PathSeparator)) {
159 // when $HOME is empty this will complete on /, however this is not tested
160 homeDir = os.Getenv("HOME")
161 prefix = fmt.Sprintf("%s%s", homeDir, prefix[1:])
162 }
163
164 return findMatches(
165 fmt.Sprintf("%s*", prefix),
166 func(path string) string {
167 if homeDir != "" {
168 newPath, err := filepath.Rel(homeDir, path)
169 if err == nil {
170 path = filepath.Join("~", newPath)
171 }
172 }
173 return fmt.Sprintf("@%s", path)
174 })
175}
176
177type PathWithBool string
178

Callers

nothing calls this directly

Calls 1

findMatchesFunction · 0.85

Tested by

no test coverage detected