Skip to content

Commit

Permalink
Merge pull request #5 from Jaezmien/main
Browse files Browse the repository at this point in the history
  • Loading branch information
isabelroses authored Apr 3, 2024
2 parents 471ab9e + b31371d commit b4c80e6
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 30 deletions.
50 changes: 22 additions & 28 deletions lua/charm-freeze/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ M.allowed_opts = {
margin = { "string", "table" },
background = "string",
theme = "string",
line_numbers = "boolean",
show_line_numbers = "boolean",
line_height = "number",
language = "string",
font = {
Expand Down Expand Up @@ -79,49 +79,43 @@ M.parse_options = function(opts)
return options
end

-- Generate the command line arguments
M.get_arguments = function(args, options)
local cmd = {}
local value = nil

table.insert(cmd, options.command)

for k, v in pairs(options) do
-- handle margin and padding sepreatly as tables
local function populate_cmd(cmd, args, tbl, prefix)
for k,v in pairs(tbl) do
-- handle margin and padding separately as tables
if k == "margin" or k == "padding" then
if type(v) == "table" then
table.insert(cmd, "--" .. k)
table.insert(cmd, "--" .. prefix .. k)
table.insert(cmd, table.concat(v, ","))
end
-- table options ('border', 'font', 'shadow')
elseif type(v) == "table" and not is_array(v) then
for _k, _v in pairs(v) do
table.insert(cmd, "--" .. k .. "." .. string.gsub(_k, "_", "-"))
if type(_v) == "boolean" then
if _v then
table.insert(cmd)
end
else
table.insert(cmd, _v)
end
end
-- handle boolean options, they are just flags with no value
elseif type(v) == "boolean" then
if v then
table.insert(cmd, "--" .. string.gsub(k, "_", "-"))
end
populate_cmd(cmd, args, v, prefix .. k .. '.')
-- handle anything that is not the command or language option
elseif k ~= "command" and k ~= "language" then
table.insert(cmd, "--" .. string.gsub(k, "_", "-"))
table.insert(cmd, "--" .. prefix .. string.gsub(k, "_", "-"))

-- if the value is a function, call it with the args, otherwise just use the value
local value = nil
if type(v) == "function" then
value = v(args)
else
value = v
end
table.insert(cmd, value)

-- Don't append the value if it's a boolean option.
if type(v) ~= "boolean" then
table.insert(cmd, value)
end
end
end
end

-- Generate the command line arguments
M.get_arguments = function(args, options)
local cmd = {}

table.insert(cmd, options.command)
populate_cmd(cmd, args, options, '')

return cmd
end
Expand Down
4 changes: 2 additions & 2 deletions tests/charm-freeze/test_all.lua
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ end

T["invalid_options.boolean"] = function()
e(function()
child.lua([[P.setup({line_numbers = "chesee"})]])
child.lua([[P.setup({show_line_numbers = "chesee"})]])
end)
end

Expand Down Expand Up @@ -78,7 +78,7 @@ end

T["valid_options.boolean"] = function()
ne(function()
child.lua([[P.setup({line_numbers = false})]])
child.lua([[P.setup({show_line_numbers = false})]])
end)
end

Expand Down

0 comments on commit b4c80e6

Please sign in to comment.