MCPcopy Index your code
hub / github.com/rclone/rclone / addLocalFiles

Function addLocalFiles

cmd/completion.go:37–71  ·  view source on GitHub ↗

Add local files to the completions being built up

(toComplete string, result cobra.ShellCompDirective, completions []string)

Source from the content-addressed store, hash-verified

35
36// Add local files to the completions being built up
37func addLocalFiles(toComplete string, result cobra.ShellCompDirective, completions []string) (cobra.ShellCompDirective, []string) {
38 path := filepath.Clean(toComplete)
39 dir, file := filepath.Split(path)
40 if dir == "" {
41 dir = "."
42 }
43 if len(dir) > 0 && dir[0] != filepath.Separator && dir[0] != '/' {
44 dir = strings.TrimRight(dir, string(filepath.Separator))
45 dir = strings.TrimRight(dir, "/")
46 }
47 fi, err := os.Stat(toComplete)
48 if err == nil {
49 if fi.IsDir() {
50 dir = toComplete
51 file = ""
52 }
53 }
54 fis, err := os.ReadDir(dir)
55 if err != nil {
56 compLogf("Failed to read directory %q: %v", dir, err)
57 return result, completions
58 }
59 for _, fi := range fis {
60 name := fi.Name()
61 if strings.HasPrefix(name, file) {
62 path := filepath.Join(dir, name)
63 if fi.IsDir() {
64 path += string(filepath.Separator)
65 result |= cobra.ShellCompDirectiveNoSpace
66 }
67 completions = append(completions, path)
68 }
69 }
70 return result, completions
71}
72
73// Add remote files to the completions being built up
74func addRemoteFiles(toComplete string, result cobra.ShellCompDirective, completions []string) (cobra.ShellCompDirective, []string) {

Callers 1

validArgsFunction · 0.85

Calls 6

compLogfFunction · 0.85
JoinMethod · 0.80
StatMethod · 0.65
ReadDirMethod · 0.65
NameMethod · 0.65
IsDirMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…