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

Function completeWithTilde

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

Source from the content-addressed store, hash-verified

207}
208
209func completeWithTilde(prefix string) []flags.Completion {
210 var homeDir string
211 if strings.HasPrefix(prefix, fmt.Sprintf("~%c", os.PathSeparator)) {
212 // when $HOME is empty this will complete on /, however this is not tested
213 homeDir = os.Getenv("HOME")
214 prefix = fmt.Sprintf("%s%s", homeDir, prefix[1:])
215 }
216
217 return findMatches(
218 fmt.Sprintf("%s*", prefix),
219 func(path string) string {
220 if homeDir != "" {
221 newPath, err := filepath.Rel(homeDir, path)
222 if err == nil {
223 path = filepath.Join("~", newPath)
224 }
225 }
226 return path
227 })
228}
229
230func checkIfFileExists(path string) (os.FileInfo, error) {
231 fileInfo, err := os.Stat(path)

Callers 7

CompleteMethod · 0.85
CompleteMethod · 0.85
CompleteMethod · 0.85
CompleteMethod · 0.85
CompleteMethod · 0.85
CompleteMethod · 0.85
CompleteMethod · 0.85

Calls 1

findMatchesFunction · 0.85

Tested by

no test coverage detected