aboutsummaryrefslogtreecommitdiff
path: root/gamemode/shared/concommands.lua
blob: 64d9a35753019e4e4571a5a50c14f31c59b1c0f3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
--[[
    Various console command helper functions
]]

local fuzzel = nrequire("fuzzel.lua")

local concmd = {}

function concmd.AutocompleteFunction(...)
    local opt = {...}
    opt = type(opt[1]) == "table" and opt[1] or opt
    return function(cmd,strargs)
        --Remove spaces and quotes, since we don't want to match them
        strargs = string.gsub(strargs,"[\" ]","")
        --Find the options that most closely resemble our command so far
        local sorted = fuzzel.fad(strargs,opt)
        --Add quotes if needed, and preppend the command to each option
        for k,v in pairs(sorted) do
            if string.find(v," ") ~= nil then
                sorted[k] = "\"" .. v .. "\""
            end
            sorted[k] = cmd .. " " .. sorted[k]
        end
        return sorted
    end
end

return concmd