diff --git a/rl.go b/rl.go index 95b1bd0..b431ad7 100644 --- a/rl.go +++ b/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,