Skip to content

Commit 4b8610b

Browse files
committed
Add perfect-match flow
1 parent 5ba4f32 commit 4b8610b

File tree

1 file changed

+23
-5
lines changed

1 file changed

+23
-5
lines changed

cmd/trygolang/main.go

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,13 +87,31 @@ func main() {
8787
}
8888
}
8989
case 1 < numberOfCandidate:
90-
fmt.Printf("There's %d candidates found\n", len(candidates))
91-
92-
for _, item := range candidates {
93-
fmt.Printf("\t%s\n", item)
90+
// 完全一致するものがあるか?
91+
isPerfectMatchFound := false
92+
for _, c := range candidates {
93+
if c == userInput {
94+
if v, ok := mapping[c]; ok {
95+
fmt.Printf("[Name] %q\n", userInput)
96+
if err := v(); err != nil {
97+
log.Fatal(err)
98+
}
99+
}
100+
101+
isPerfectMatchFound = true
102+
break
103+
}
94104
}
95105

96-
goto nextinput
106+
if !isPerfectMatchFound {
107+
fmt.Printf("There's %d candidates found\n", len(candidates))
108+
109+
for _, item := range candidates {
110+
fmt.Printf("\t%s\n", item)
111+
}
112+
113+
goto nextinput
114+
}
97115
}
98116

99117
if *onetime {

0 commit comments

Comments
 (0)