Merge pull request #464 from remakeelectric/pulls/list-operations
authorJo-Philipp Wich <jow@openwrt.org>
Thu, 17 Dec 2015 01:39:23 +0000 (02:39 +0100)
committerJo-Philipp Wich <jow@openwrt.org>
Thu, 17 Dec 2015 01:39:23 +0000 (02:39 +0100)
get/set list operations and documentation

modules/luci-base/luasrc/model/uci.lua
modules/luci-base/luasrc/model/uci.luadoc

index 1659137..577c6cd 100644 (file)
@@ -111,7 +111,7 @@ function Cursor.get_list(self, config, section, option)
                local val = self:get(config, section, option)
                return ( type(val) == "table" and val or { val } )
        end
-       return nil
+       return {}
 end
 
 function Cursor.get_first(self, conf, stype, opt, def)
@@ -139,6 +139,9 @@ end
 
 function Cursor.set_list(self, config, section, option, value)
        if config and section and option then
+               if not value or #value == 0 then
+                       return self:delete(config, section, option)
+               end
                return self:set(
                        config, section, option,
                        ( type(value) == "table" and value or { value } )
index 7591b68..49093c7 100644 (file)
@@ -88,7 +88,8 @@ Get an option or list and return values as table.
 @param config  UCI config
 @param section UCI section name
 @param option  UCI option
-@return                        UCI value
+@return                table.  If the option was not found, you will simply get
+--             an empty table.
 ]]
 
 ---[[
@@ -104,14 +105,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
 @name Cursor.set_list
 @param config  UCI config
 @param section UCI section name
 @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
 ]]