improve conver_user_opts function readable (#441)

This commit is contained in:
Raphael
2021-01-17 17:34:58 +08:00
committed by GitHub
parent 9f58834d04
commit c2039ca78d

View File

@@ -4,9 +4,12 @@ local extensions = require('telescope._extensions').manager
local config = require('telescope.config')
local command = {}
local arg_value = {
['nil'] = nil,['""'] = '',['"'] = ''
}
local bool_type = {
['false'] = false,
['true'] = true
['false'] = false,['true'] = true
}
-- convert command line string arguments to
@@ -18,6 +21,7 @@ local function convert_user_opts(user_opts)
['boolean'] = function(key,val)
if val == 'false' then
user_opts[key] = false
return
end
user_opts[key] = true
end,
@@ -25,15 +29,11 @@ local function convert_user_opts(user_opts)
user_opts[key] = tonumber(val)
end,
['string'] = function(key,val)
if val == 'nil' then
user_opts[key] = nil
end
if val == '""' then
user_opts[key] = ''
end
if val == '"' then
user_opts[key] = ''
if arg_value[val] ~= nil then
user_opts[key] = arg_value[val]
return
end
if bool_type[val] ~= nil then
user_opts[key] = bool_type[val]
end