Skip to content

Commit e160ad9

Browse files
akerl-unprivakerl
authored andcommitted
handle first instance of a matching role (#13)
1 parent d6e5db4 commit e160ad9

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

travel/main.go

+21-1
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,25 @@ func (i *Itinerary) executeHop(thisHop hop, c creds.Creds) (creds.Creds, error)
167167
return newCreds, err
168168
}
169169

170+
func stringInSlice(list []string, key string) bool {
171+
for _, item := range list {
172+
if item == key {
173+
return true
174+
}
175+
}
176+
return false
177+
}
178+
179+
func sliceUnion(a []string, b []string) []string {
180+
var res []string
181+
for _, item := range a {
182+
if stringInSlice(b, item) {
183+
res = append(res, item)
184+
}
185+
}
186+
return res
187+
}
188+
170189
func (i *Itinerary) getPath() ([]hop, error) { //revive:disable-line:cyclomatic
171190
var paths [][]hop
172191
mapProfiles := make(map[string]bool)
@@ -202,7 +221,8 @@ func (i *Itinerary) getPath() ([]hop, error) { //revive:disable-line:cyclomatic
202221
}
203222

204223
allProfiles := keys(mapProfiles)
205-
profile, err := i.getPrompt().Filtered(i.ProfileName, allProfiles, "Desired target profile:")
224+
unionProfiles := sliceUnion(allProfiles, i.ProfileName)
225+
profile, err := i.getPrompt().Filtered(unionProfiles, allProfiles, "Desired target profile:")
206226
if err != nil {
207227
return []hop{}, err
208228
}

0 commit comments

Comments
 (0)