]> git.ipfire.org Git - thirdparty/openwrt.git/commitdiff
cli: extend remove call to allow passing values directly
authorFelix Fietkau <nbd@nbd.name>
Thu, 3 Apr 2025 09:51:41 +0000 (11:51 +0200)
committerFelix Fietkau <nbd@nbd.name>
Fri, 11 Apr 2025 08:41:12 +0000 (10:41 +0200)
This simplifies script or API usage of this command to remove values directly
without having to calculate the index

Signed-off-by: Felix Fietkau <nbd@nbd.name>
package/utils/cli/files/usr/share/ucode/cli/object-editor.uc

index 0a447540644401f5797734a04a650357fe04fd34..1f36ee9d0748b7bb861f7d24f60ef4c037ca09bd 100644 (file)
@@ -135,8 +135,14 @@ export function remove_call(ctx, argv, named)
                if (!data)
                        continue;
 
-               for (let idx in val)
+               for (let idx in val) {
+                       if (idx != "" + +idx) {
+                               let cur_idx = index(data, idx);
+                               if (cur_idx >= 0)
+                                       idx = cur_idx + 1;
+                       }
                        data[+idx - 1] = null;
+               }
 
                cur_obj[name] = filter(data, (v) => v != null);
                if (cur.attribute_allow_empty && !length(cur_obj[name]))