-
Notifications
You must be signed in to change notification settings - Fork 0
/
repo_options.go
68 lines (55 loc) · 1.69 KB
/
repo_options.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package prompts
import (
"fmt"
"strings"
"github.com/manifoldco/promptui"
)
type PartialRepo struct {
Name string `json:"name"`
Http_url string `json:"html_url"`
Ssh_url string `json:"ssh_url"`
Description string `json:"description"`
Private bool `json:"private"`
}
func RepoPrompt(repos []PartialRepo) (PartialRepo, error) {
templates := &promptui.SelectTemplates{
Label: " {{ .Name | faint }}?",
Active: "-> {{ .Name | blue }}",
Inactive: " {{ .Name | cyan }}",
Selected: " {{ .Name | red | cyan }}",
Details: `
--------- Repository ----------
{{ "Name:" | faint }} {{ .Name }}
{{ "Description:" | faint }} {{ .Description }}
{{ "HTTP URL:" | faint }} {{ .Http_url }}
{{ "SSH URL:" | faint }} {{ .Ssh_url }}
{{ "Private:" | faint }} {{ .Private }}
`,
}
searcher := func(input string, index int) bool {
repo := repos[index]
name := strings.Replace(strings.ToLower(repo.Name), " ", "", -1)
input = strings.Replace(strings.ToLower(input), " ", "", -1)
return strings.Contains(name, input)
}
prompt := promptui.Select{
Label: "Select a repository",
Items: repos,
Templates: templates,
Size: 4,
Searcher: searcher,
}
i, _, err := prompt.Run()
if err != nil {
fmt.Printf("Prompt failed %v\n", err)
// return _, errors.New("Prompt failed")
}
// fmt.Printf("You chose repo %d: %s\n", i+1, repos[i].Name)
// fmt.Printf("http url: %s\n", repos[i].Http_url)
// fmt.Printf("ssh url: %s\n", repos[i].Ssh_url)
// should probably return the whole *partial* repo object just incase the
// user wants to clone ssh OR html.
// - will probably just start with http implementation
// return // repos[i].Name
return repos[i], nil
}