From: Jo-Philipp Wich Date: Wed, 24 Aug 2022 22:43:07 +0000 (+0200) Subject: unet-cli: use modern ucode syntax X-Git-Url: http://git.lede-project.org./?a=commitdiff_plain;h=a1850a0f7b5b36d997ed6add65b84f76e343d130;p=project%2Funetd.git unet-cli: use modern ucode syntax Refactor various places in the script to use modern syntax, such as template strings or `in` lookups. Also introduce a simple `assert()` helper function to deal with the repeated `if (!cond) { warn(msg); exit(1) }` pattern. Signed-off-by: Jo-Philipp Wich --- diff --git a/scripts/unet-cli b/scripts/unet-cli index c5e7025..883f1ba 100755 --- a/scripts/unet-cli +++ b/scripts/unet-cli @@ -2,13 +2,19 @@ let fs = require("fs"); -let script_dir = sourcepath(0, true); -if (fs.basename(script_dir) == "scripts") { - unet_tool = fs.dirname(script_dir) + "/unet-tool"; - if (!fs.access(unet_tool, "x")) { - warn("unet-tool missing\n"); +function assert(cond, message) { + if (!cond) { + warn(message, "\n"); exit(1); } + + return true; +} + +let script_dir = sourcepath(0, true); +if (fs.basename(script_dir) == "scripts") { + unet_tool = `${fs.dirname(script_dir)}/unet-tool`; + assert(fs.access(unet_tool, "x"), "unet-tool missing"); } else { unet_tool = "unet-tool"; } @@ -21,55 +27,59 @@ defaults = { keepalive: 10, }; +const usage_message = ` +Usage: ${fs.basename(sourcepath())} [] [] [