-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathresolve.go
53 lines (48 loc) · 1.25 KB
/
resolve.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
package main
import "strings"
// Resolve asks the user to resolve the identifiers
func Resolve(identifiers []*Identifier, config *Config, p prompt) (map[string]map[string]string, error) {
if err := p.start(); err != nil {
return nil, err
}
defer p.close()
values := make(map[string]map[string]string)
scopeAsked := make(map[string]bool)
for _, id := range identifiers {
if found(values, id) || id.scope == "" || scopeAsked[id.scope] {
continue
}
scopeAsked[id.scope] = true
idg := collect(identifiers, id.scope)
if len(idg.keys) == 0 {
continue
}
history := config.collectScopedPairHistory(idg)
if len(history) == 0 {
continue
}
p.setHistory(history)
text, err := p.prompt(idg.prompt())
if err != nil {
return nil, err
}
xs := strings.Split(strings.TrimSuffix(text, "\n"), ", ")
if len(xs) == len(idg.keys) {
for i, key := range idg.keys {
insert(values, &Identifier{scope: id.scope, key: key}, strings.Replace(xs[i], ",\\ ", ", ", -1))
}
}
}
for _, id := range identifiers {
if found(values, id) {
continue
}
p.setHistory(config.collectHistory(id))
text, err := p.prompt(id.prompt())
if err != nil {
return nil, err
}
insert(values, id, strings.TrimSuffix(text, "\n"))
}
return values, nil
}