mirror of
https://github.com/Hilbis/Hilbish
synced 2025-04-26 23:43:22 +00:00
feat: implement alias for completion groups of type list
This commit is contained in:
parent
8437a3b4bb
commit
8ea0667bdb
17
rl.go
17
rl.go
@ -139,9 +139,11 @@ func newLineReader(prompt string, noHist bool) *lineReader {
|
||||
items := []string{}
|
||||
itemDescriptions := make(map[string]string)
|
||||
itemDisplays := make(map[string]string)
|
||||
itemAliases := make(map[string]string)
|
||||
|
||||
util.ForEach(luaCompItems.AsTable(), func(lkey rt.Value, lval rt.Value) {
|
||||
if keytyp := lkey.Type(); keytyp == rt.StringType {
|
||||
// TODO: remove in 3.0
|
||||
// ['--flag'] = {'description', '--flag-alias'}
|
||||
// OR
|
||||
// ['--flag'] = {description = '', alias = '', display = ''}
|
||||
@ -156,19 +158,21 @@ func newLineReader(prompt string, noHist bool) *lineReader {
|
||||
itemDescription, ok := vlTbl.Get(rt.IntValue(1)).TryString()
|
||||
if !ok {
|
||||
// if we can't get it by number index, try by string key
|
||||
itemDescription, ok = vlTbl.Get(rt.StringValue("description")).TryString()
|
||||
if !ok {
|
||||
// TODO: error?
|
||||
return
|
||||
}
|
||||
itemDescription, _ = vlTbl.Get(rt.StringValue("description")).TryString()
|
||||
}
|
||||
itemDescriptions[itemName] = itemDescription
|
||||
|
||||
// display
|
||||
// this is optional, so only act when we get it and it's a string
|
||||
if itemDisplay, ok := vlTbl.Get(rt.StringValue("display")).TryString(); ok {
|
||||
itemDisplays[itemName] = itemDisplay
|
||||
}
|
||||
|
||||
itemAlias, ok := vlTbl.Get(rt.IntValue(2)).TryString()
|
||||
if !ok {
|
||||
// if we can't get it by number index, try by string key
|
||||
itemAlias, _ = vlTbl.Get(rt.StringValue("alias")).TryString()
|
||||
}
|
||||
itemAliases[itemName] = itemAlias
|
||||
} else if keytyp == rt.IntType {
|
||||
vlStr, ok := lval.TryString()
|
||||
if !ok {
|
||||
@ -192,6 +196,7 @@ func newLineReader(prompt string, noHist bool) *lineReader {
|
||||
|
||||
compGroups = append(compGroups, &readline.CompletionGroup{
|
||||
DisplayType: dispType,
|
||||
Aliases: itemAliases,
|
||||
Descriptions: itemDescriptions,
|
||||
ItemDisplays: itemDisplays,
|
||||
Suggestions: items,
|
||||
|
Loading…
x
Reference in New Issue
Block a user