uci:set_list: Delete option if the list is empty
Allows lists fetched with get_list to be modified and simply passed back to set_list. Explicitly calling set_list() with an empty list is clearly requesting that there be zero list items, ie, deletion of the option altogether. Signed-off-by: Karl Palsson <karlp@remake.is>
This commit is contained in:
parent
f0083abed1
commit
879d9ff2b8
2 changed files with 6 additions and 2 deletions
|
@ -139,6 +139,9 @@ end
|
||||||
|
|
||||||
function Cursor.set_list(self, config, section, option, value)
|
function Cursor.set_list(self, config, section, option, value)
|
||||||
if config and section and option then
|
if config and section and option then
|
||||||
|
if not value or #value == 0 then
|
||||||
|
return self:delete(config, section, option)
|
||||||
|
end
|
||||||
return self:set(
|
return self:set(
|
||||||
config, section, option,
|
config, section, option,
|
||||||
( type(value) == "table" and value or { value } )
|
( type(value) == "table" and value or { value } )
|
||||||
|
|
|
@ -104,14 +104,15 @@ Get the given option from the first section with the given type.
|
||||||
]]
|
]]
|
||||||
|
|
||||||
---[[
|
---[[
|
||||||
Set given values as list.
|
Set given values as list. Setting a list option to an empty list
|
||||||
|
has the same effect as deleting the option.
|
||||||
|
|
||||||
@class function
|
@class function
|
||||||
@name Cursor.set_list
|
@name Cursor.set_list
|
||||||
@param config UCI config
|
@param config UCI config
|
||||||
@param section UCI section name
|
@param section UCI section name
|
||||||
@param option UCI option
|
@param option UCI option
|
||||||
@param value UCI value
|
@param value value or table. Raw values will become a single item table.
|
||||||
@return Boolean whether operation succeeded
|
@return Boolean whether operation succeeded
|
||||||
]]
|
]]
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue