complete options
@@ -121,13 +121,15 @@ function _complete_option_kv_v(options, current, completing, name, value)
end
-- match values starts with value first
+ local found_candidates = {}
for _, v in ipairs(_find_candidates(values, value)) do
if no_key then
- _print_candidate(true, "%s", v)
+ table.insert(found_candidates, { value = v, is_complete = true })
else
- _print_candidate(true, "--%s=%s", name, v)
+ table.insert(found_candidates, { value = format("--%s=%s", name, v), is_complete = true })
end
end
+ _print_candidates(found_candidates)
-- whether any candidates has been found, finish complete since we don't have more info
return true
@@ -142,11 +144,13 @@ function _complete_option_kv_k(options, current, completing, name)
opcandi[opt[2]] = opt
end
end
-
+ local found_candidates = {}
for _, k in ipairs(_find_candidates((table.keys(opcandi)), name)) do
local opt = opcandi[k]
- _print_candidate((opt[3] == "k"), (opt[3] == "k") and "--%s" or "--%s=", opt[2])
+ local name = format((opt[3] == "k") and "--%s" or "--%s=", opt[2])
+ table.insert(found_candidates, { value = name, description = opt[5], is_complete = (opt[3] == "k") })
end
+ _print_candidates(found_candidates)
return true
end
@@ -190,7 +194,7 @@ function _complete_option_v(options, current, completing)
optvs = v
end
end
-
+ local found_candidates = {}
if opt then
-- show candidates of values
local values = opt.values
@@ -199,14 +203,12 @@ function _complete_option_v(options, current, completing)
end
for _, v in ipairs(values) do
if tostring(v):startswith(completing) then
- _print_candidate(true, "%s", v)
+ table.insert(found_candidates, { value = v, is_complete = true })
end
end
- return true
end
- if optvs then
-
+ if optvs and #found_candidates == 0 then
-- show candidates of values
local values = optvs.values
if type(values) == "function" then
@@ -214,13 +216,12 @@ function _complete_option_v(options, current, completing)
end
for _, v in ipairs(values) do
if tostring(v):startswith(completing) then
- _print_candidate(true, "%s", v)
+ table.insert(found_candidates, { value = v, is_complete = true })
end
end
- return true
end
-
- return false
+ _print_candidates(found_candidates)
+ return #found_candidates > 0
end
function _complete_option(options, segs, completing)
