Skip to content

Commit 03342d0

Browse files
authored
autocomplete: allow completion based on name/detail (#165)
Fixes #48 https://github.com/user-attachments/assets/8296cbef-29ba-4c82-a072-46affbef7ce1 Signed-off-by: Abhishek Kumar <[email protected]>
1 parent b6f1408 commit 03342d0

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
@@ -465,7 +465,7 @@ func (t *autoCompleter) Do(line []rune, pos int) (options [][]rune, offset int)
465465
})
466466
}
467467
for _, item := range argOptions {
468-
if strings.HasPrefix(item.Value, argInput) {
468+
if strings.HasPrefix(item.Value, argInput) || (len(item.Detail) > 0 && strings.HasPrefix(item.Detail, argInput)) {
469469
filteredOptions = append(filteredOptions, item)
470470
}
471471
}
@@ -476,12 +476,14 @@ func (t *autoCompleter) Do(line []rune, pos int) (options [][]rune, offset int)
476476
}
477477
for _, item := range filteredOptions {
478478
option := item.Value + " "
479-
if len(filteredOptions) > 1 && len(item.Detail) > 0 {
479+
if len(filteredOptions) > 0 && len(item.Detail) > 0 {
480480
option += fmt.Sprintf("(%v)", item.Detail)
481481
}
482482
if strings.HasPrefix(option, argInput) {
483483
options = append(options, []rune(option[len(argInput):]))
484484
offset = len(argInput)
485+
} else if len(item.Detail) > 0 && strings.HasPrefix(item.Detail, argInput) {
486+
options = append(options, []rune(option))
485487
}
486488
}
487489
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)