(prompt, name string, validRemotes []string, validators ...PromptValidator)
| 159 | } |
| 160 | |
| 161 | func PromptURLWithRemote(prompt, name string, validRemotes []string, validators ...PromptValidator) (string, error) { |
| 162 | if len(validRemotes) == 0 { |
| 163 | return Prompt(prompt, name, validators...) |
| 164 | } |
| 165 | |
| 166 | sort.Strings(validRemotes) |
| 167 | |
| 168 | for { |
| 169 | _, _ = fmt.Fprintln(os.Stderr, "\nDetected projects:") |
| 170 | |
| 171 | for i, remote := range validRemotes { |
| 172 | _, _ = fmt.Fprintf(os.Stderr, "[%d]: %v\n", i+1, remote) |
| 173 | } |
| 174 | |
| 175 | _, _ = fmt.Fprintf(os.Stderr, "\n[0]: Another project\n\n") |
| 176 | _, _ = fmt.Fprintf(os.Stderr, "Select option: ") |
| 177 | |
| 178 | line, err := bufio.NewReader(os.Stdin).ReadString('\n') |
| 179 | if err != nil { |
| 180 | return "", err |
| 181 | } |
| 182 | |
| 183 | line = strings.TrimSpace(line) |
| 184 | |
| 185 | index, err := strconv.Atoi(line) |
| 186 | if err != nil || index < 0 || index > len(validRemotes) { |
| 187 | _, _ = fmt.Fprintln(os.Stderr, "invalid input") |
| 188 | continue |
| 189 | } |
| 190 | |
| 191 | // if user want to enter another project url break this loop |
| 192 | if index == 0 { |
| 193 | break |
| 194 | } |
| 195 | |
| 196 | return validRemotes[index-1], nil |
| 197 | } |
| 198 | |
| 199 | return Prompt(prompt, name, validators...) |
| 200 | } |
| 201 | |
| 202 | func PromptCredential(target, name string, credentials []auth.Credential, choices []string) (auth.Credential, int, error) { |
| 203 | if len(credentials) == 0 && len(choices) == 0 { |
no test coverage detected