Skip to content

Commit 22a3ae0

Browse files
committed
autocomplete: allow completion based on name/detail
Fixes #48 Signed-off-by: Abhishek Kumar <[email protected]>
1 parent a6552ee commit 22a3ae0

File tree

2 files changed

+23
-6
lines changed

2 files changed

+23
-6
lines changed

cli/completer.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ func (t *autoCompleter) Do(line []rune, pos int) (options [][]rune, offset int)
410410
return argOptions[i].Value < argOptions[j].Value
411411
})
412412
for _, item := range argOptions {
413-
if strings.HasPrefix(item.Value, argInput) {
413+
if strings.HasPrefix(item.Value, argInput) || (len(item.Detail) > 0 && strings.HasPrefix(item.Detail, argInput)) {
414414
filteredOptions = append(filteredOptions, item)
415415
}
416416
}
@@ -421,12 +421,14 @@ func (t *autoCompleter) Do(line []rune, pos int) (options [][]rune, offset int)
421421
}
422422
for _, item := range filteredOptions {
423423
option := item.Value + " "
424-
if len(filteredOptions) > 1 && len(item.Detail) > 0 {
424+
if len(filteredOptions) > 0 && len(item.Detail) > 0 {
425425
option += fmt.Sprintf("(%v)", item.Detail)
426426
}
427427
if strings.HasPrefix(option, argInput) {
428428
options = append(options, []rune(option[len(argInput):]))
429429
offset = len(argInput)
430+
} else if len(item.Detail) > 0 && strings.HasPrefix(item.Detail, argInput) {
431+
options = append(options, []rune(option))
430432
}
431433
}
432434
return

vendor/github.com/chzyer/readline/complete.go

Lines changed: 19 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)