unet-cli: pass host object to set_host()
authorFelix Fietkau <nbd@nbd.name>
Thu, 25 Aug 2022 10:40:17 +0000 (12:40 +0200)
committerFelix Fietkau <nbd@nbd.name>
Thu, 25 Aug 2022 10:41:29 +0000 (12:41 +0200)
Avoids accessing global net_data from within the function

Signed-off-by: Felix Fietkau <nbd@nbd.name>
scripts/unet-cli

index f00c817021e7618c266a938d81f98dabd1ad30fa..c10b54254637df8b1fc6b4cbcede5a6d2e26d4d4 100755 (executable)
@@ -213,9 +213,7 @@ function set_fields(object, list) {
                set_field(list[f], object, f, args[f]);
 }
 
-function set_host(name) {
-       let host = net_data.hosts[name];
-
+function set_host(host) {
        set_fields(host, {
                key: "string",
                endpoint: "string",
@@ -372,12 +370,12 @@ case 'set-config':
 case 'add-host':
        net_data.hosts[hostname] = {};
        assert(args.key, "Missing host key");
-       set_host(hostname);
+       set_host(net_data.hosts[hostname]);
        break;
 
 case 'set-host':
        assert(net_data.hosts[hostname], `Host '${hostname}' does not exist`);
-       set_host(hostname);
+       set_host(net_data.hosts[hostname]);
        break;
 
 case 'add-service':