From a2268087ca0e2e0037ee4f0c23783b8b5306c3bd Mon Sep 17 00:00:00 2001 From: Martin Karkowski Date: Wed, 4 Aug 2021 14:55:56 +0200 Subject: [PATCH] adding force-emit flag --- lib/cli/runNopeBackend.ts | 45 ++++++++++++++++++++++++++++----------- 1 file changed, 33 insertions(+), 12 deletions(-) diff --git a/lib/cli/runNopeBackend.ts b/lib/cli/runNopeBackend.ts index 6d7c2dc..0035dde 100644 --- a/lib/cli/runNopeBackend.ts +++ b/lib/cli/runNopeBackend.ts @@ -2,10 +2,9 @@ * @author Martin Karkowski * @email m.karkowski@zema.de * @create date 2020-11-11 13:27:58 - * @modify date 2021-05-13 11:30:38 + * @modify date 2021-08-03 17:16:50 * @desc [description] * - * TODO: fix imports and make extra function to load communication-bridge. */ import { ArgumentParser } from "argparse"; @@ -79,12 +78,20 @@ export async function readInArgs( type: "string", dest: "params" }); - parser.addArgument(["-s", "--skipLoadingConfig"], { + parser.addArgument(["-s", "--skip-loading-config"], { help: "Flag to prevent loading the elements defined in the settings.json.", action: "append", nargs: "?", dest: "skipLoadingConfig" }); + + parser.addArgument(["--force-emit"], { + help: "Forces emitting the events of the system. Otherwise, only subscribed events are emitted.", + action: "append", + nargs: "?", + dest: "forceEmittingUpdates" + }); + parser.addArgument(["-l", "--log"], { help: "Specify the Logger Level. Defaults to \"info\". Valid values are: " + @@ -100,6 +107,7 @@ export async function readInArgs( params?: string; skipLoadingConfig?: boolean; log: LoggerLevel; + forceEmittingUpdates?: boolean; } = parser.parseArgs(); if (args.params === "not-provided") { @@ -107,6 +115,7 @@ export async function readInArgs( } args.skipLoadingConfig = Array.isArray(args.skipLoadingConfig); + args.forceEmittingUpdates = Array.isArray(args.forceEmittingUpdates); return args; } @@ -118,7 +127,11 @@ export async function runNopeBackend( file?: string; channel?: validLayerOrMirror; params?: string; + // Flag to prevent loading the configuration skipLoadingConfig?: boolean; + // Flag to force sending updates. + forceEmittingUpdates?: boolean; + // Level of the logger. log?: LoggerLevel; } = {} ): Promise { @@ -158,9 +171,9 @@ export async function runNopeBackend( if (!Object.getOwnPropertyNames(validLayers).includes(args.channel)) { logger.error( "Invalid Channel. Please use the following values. " + - Object.getOwnPropertyNames(validLayers) - .map((item) => "\"" + item + "\"") - .join(", ") + Object.getOwnPropertyNames(validLayers) + .map((item) => "\"" + item + "\"") + .join(", ") ); return; } @@ -170,11 +183,18 @@ export async function runNopeBackend( if (args.params != "not-provided") { try { - opts.params = JSON.parse(args.params); + try { + // We try to parse the data. + opts.params = JSON.parse(args.params); + } catch (e) { + opts.params = JSON.parse("\"" + args.params + "\""); + } } catch (e) { logger.error( "Unable to parse the Parameters for the channel. Please use valid JSON!" ); + logger.error(args.params[0]); + logger.error(e); return; } } @@ -188,8 +208,8 @@ export async function runNopeBackend( } catch (e) { logger.error( "Unable to load the Packages defined in " + - args.file + - " See Output for detailled information", + args.file + + " See Output for detailled information", e ); return; @@ -200,7 +220,8 @@ export async function runNopeBackend( try { loader = getPackageLoader({ communicator: getLayer(args.channel, opts.params, "debug"), - logger: getNopeLogger("dispatcher", "debug") + logger: getNopeLogger("dispatcher", "debug"), + forceEmittingUpdates: args.forceEmittingUpdates, }); } catch (e) { getNopeLogger("cli", "info").error("failed to load the Packages", e); @@ -215,8 +236,8 @@ export async function runNopeBackend( } catch (e) { logger.error( "Unable to load the Packages defined in " + - args.file + - " See Output for detailled information", + args.file + + " See Output for detailled information", e ); return;