MCPcopy Index your code
hub / github.com/git-bug/git-bug / PromptURLWithRemote

Function PromptURLWithRemote

commands/input/prompt.go:161–200  ·  view source on GitHub ↗
(prompt, name string, validRemotes []string, validators ...PromptValidator)

Source from the content-addressed store, hash-verified

159}
160
161func 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
202func PromptCredential(target, name string, credentials []auth.Credential, choices []string) (auth.Credential, int, error) {
203 if len(credentials) == 0 && len(choices) == 0 {

Callers 2

promptURLFunction · 0.92
promptProjectURLFunction · 0.92

Calls 2

PromptFunction · 0.85
ReadStringMethod · 0.65

Tested by

no test coverage detected