Skip to content

Commit

Permalink
feat: make addParamsNoExpand method
Browse files Browse the repository at this point in the history
  • Loading branch information
FedeAbella authored and xixiaofinland committed Nov 4, 2024
1 parent 6090f64 commit 840136c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 10 deletions.
2 changes: 1 addition & 1 deletion lua/sf/md.lua
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ H.retrieve_md = function(type, name, cb)
U.get_sf_root()

local type_name = string.format("%s:%s", type, name)
local cmd = B:new():cmd("project"):act("retrieve start"):addParams("-m", type_name, false):build()
local cmd = B:new():cmd("project"):act("retrieve start"):addParamsNoExpand("-m", type_name):build()
T.run(cmd, cb)
end

Expand Down
32 changes: 23 additions & 9 deletions lua/sf/sub/cmd_builder.lua
Original file line number Diff line number Diff line change
Expand Up @@ -65,18 +65,32 @@ end
function CommandBuilder:addParams(...)
local args = { ... }
if type(args[1]) == "table" then
-- If a table is passed, assume it's a list of flag-value pairs. If the value is also a table, it can contain its own value key, and an expand key indicating if the value should be expanded
-- If a table is passed, assume it's a list of flag-value pairs
for flag, value in pairs(args[1]) do
if type(value) == "table" then
self.params[flag] = { value = value.value, expand = value.expand }
else
self.params[flag] = { value = value }
end
self.params[flag] = { value = value, expand = true }
end
else
-- If individual arguments are passed, assume it's a single flag-value pair
local flag, value = args[1], args[2] or ""
self.params[flag] = { value = value, expand = true }
end
return self
end

---Add one or more parameters, but don't expand the values
---@param ... string|table Either a flag and value as separate arguments, or a table of flag-value pairs
---@return CommandBuilder
function CommandBuilder:addParamsNoExpand(...)
local args = { ... }
if type(args[1]) == "table" then
-- If a table is passed, assume it's a list of flag-value pairs
for flag, value in pairs(args[1]) do
self.params[flag] = { value = value, expand = false }
end
else
-- If individual arguments are passed, assume it's a single flag-value pair, and optionally a third argument to indicate whether the param value should be expanded
local flag, value, expand = args[1], args[2] or "", (args[3] == nil and true) or args[3]
self.params[flag] = { value = value, expand = expand }
-- If individual arguments are passed, assume it's a single flag-value pair
local flag, value = args[1], args[2] or ""
self.params[flag] = { value = value, expand = false }
end
return self
end
Expand Down

0 comments on commit 840136c

Please sign in to comment.