do command completion This is called by the command completion scripts using a hidden __complete or __completeNoDesc commands.
(cmd *cobra.Command, args []string, toComplete string)
| 112 | // |
| 113 | // This is called by the command completion scripts using a hidden __complete or __completeNoDesc commands. |
| 114 | func validArgs(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { |
| 115 | compLogf("ValidArgsFunction called with args=%q toComplete=%q", args, toComplete) |
| 116 | |
| 117 | fixBug := -1 |
| 118 | if useColonWorkaround { |
| 119 | // Work around what I think is a bug in cobra's bash |
| 120 | // completion which seems to be splitting the arguments on : |
| 121 | // Or there is something I don't understand - ncw |
| 122 | args = append(args, toComplete) |
| 123 | colonArg := -1 |
| 124 | for i, arg := range args { |
| 125 | if arg == ":" { |
| 126 | colonArg = i |
| 127 | } |
| 128 | } |
| 129 | if colonArg > 0 { |
| 130 | newToComplete := strings.Join(args[colonArg-1:], "") |
| 131 | fixBug = len(newToComplete) - len(toComplete) |
| 132 | toComplete = newToComplete |
| 133 | } |
| 134 | compLogf("...shuffled args=%q toComplete=%q", args, toComplete) |
| 135 | } |
| 136 | |
| 137 | result := cobra.ShellCompDirectiveDefault |
| 138 | completions := []string{} |
| 139 | |
| 140 | // See whether we have a valid remote yet |
| 141 | _, err := fspath.Parse(toComplete) |
| 142 | parseOK := err == nil |
| 143 | hasColon := strings.ContainsRune(toComplete, ':') |
| 144 | validRemote := parseOK && hasColon |
| 145 | compLogf("valid remote = %v", validRemote) |
| 146 | |
| 147 | // Add remotes for completion |
| 148 | if !validRemote { |
| 149 | completions = addRemotes(toComplete, completions) |
| 150 | } |
| 151 | |
| 152 | // Add local files for completion |
| 153 | if !validRemote { |
| 154 | result, completions = addLocalFiles(toComplete, result, completions) |
| 155 | } |
| 156 | |
| 157 | // Add remote files for completion |
| 158 | if validRemote { |
| 159 | result, completions = addRemoteFiles(toComplete, result, completions) |
| 160 | } |
| 161 | |
| 162 | // If using bug workaround, adjust completions to start with : |
| 163 | if useColonWorkaround && fixBug >= 0 { |
| 164 | for i := range completions { |
| 165 | if len(completions[i]) >= fixBug { |
| 166 | completions[i] = completions[i][fixBug:] |
| 167 | } |
| 168 | } |
| 169 | } |
| 170 | |
| 171 | return completions, result |
nothing calls this directly
no test coverage detected
searching dependent graphs…