MCPcopy Create free account
hub / github.com/52funny/pikpakcli / completeRemotePath

Method completeRemotePath

internal/shell/shell.go:340–390  ·  view source on GitHub ↗
(prefix string, onlyDirs bool)

Source from the content-addressed store, hash-verified

338}
339
340func (c *shellAutoCompleter) completeRemotePath(prefix string, onlyDirs bool) ([][]rune, int) {
341 currentPath := c.currentPath()
342 targetPath := resolveShellPath(currentPath, prefix)
343 basePrefix := prefix
344 if strings.TrimSpace(prefix) == "" {
345 targetPath = currentPath
346 basePrefix = ""
347 }
348
349 parentPath := targetPath
350 namePrefix := ""
351 if prefix != "" && !strings.HasSuffix(prefix, "/") {
352 parentPath = path.Dir(targetPath)
353 if parentPath == "." {
354 parentPath = "/"
355 }
356 namePrefix = path.Base(targetPath)
357 }
358
359 parentID := ""
360 var err error
361 if parentPath != "/" {
362 parentID, err = c.fileStatSource.GetPathFolderId(parentPath)
363 if err != nil {
364 return nil, len([]rune(basePrefix))
365 }
366 }
367
368 files, err := c.fileStatSource.GetFolderFileStatList(parentID)
369 if err != nil {
370 return nil, len([]rune(basePrefix))
371 }
372
373 candidates := make([]string, 0)
374 for _, file := range files {
375 if onlyDirs && file.Kind != api.FileKindFolder {
376 continue
377 }
378 if !strings.HasPrefix(file.Name, namePrefix) {
379 continue
380 }
381
382 remaining := file.Name[len(namePrefix):]
383 if file.Kind == api.FileKindFolder {
384 remaining += "/"
385 }
386 candidates = append(candidates, escapeShellCompletion(remaining))
387 }
388
389 return toRuneCandidates(candidates), len([]rune(basePrefix))
390}
391
392func completeLocalPath(prefix string, onlyDirs bool) ([][]rune, int) {
393 expandedPrefix := utils.ExpandLocalPath(prefix)

Callers 1

DoMethod · 0.95

Calls 5

resolveShellPathFunction · 0.85
escapeShellCompletionFunction · 0.85
toRuneCandidatesFunction · 0.85
GetPathFolderIdMethod · 0.65
GetFolderFileStatListMethod · 0.65

Tested by

no test coverage detected