adding possibility to use different protocol

This commit is contained in:
Martin Karkowski 2021-08-04 14:57:03 +02:00
parent e5f9aed248
commit 36f346cea1

View File

@ -9,7 +9,7 @@
import { ArgumentParser } from "argparse";
import * as inquirer from "inquirer";
import { promisify } from "util";
import { getLayer } from "../../../lib/communication/getLayer";
import { getLayer, layerDefaultParameters, validLayers } from "../../../lib/communication/getLayer";
import { getDispatcher } from "../../../lib/dispatcher/getDispatcher";
import { nopeDispatcherManager } from "../../../lib/dispatcher/nopeDispatcherManager";
import { getNopeLogger } from "../../../lib/logger/getLogger";
@ -79,6 +79,18 @@ export async function interact(
dest: "port"
});
parser.addArgument(["-c", "--channel"], {
help:
"The Communication Channel, which should be used. Possible Values are: " +
// Display all Options:
Object.getOwnPropertyNames(validLayers)
.map((item) => "\"" + item + "\"")
.join(", "),
defaultValue: "event",
type: "string",
dest: "channel"
});
parser.addArgument(["-l", "--log"], {
help:
"Specify the Logger Level. Defaults to \"info\". Valid values are: " +
@ -90,6 +102,23 @@ export async function interact(
const args = parser.parseArgs();
if (!Object.getOwnPropertyNames(validLayers).includes(args.channel)) {
console.error(
"Invalid Channel. Please use the following values. " +
Object.getOwnPropertyNames(validLayers)
.map((item) => "\"" + item + "\"")
.join(", ")
);
return;
}
if (args.channel === "io-client") {
args.params = "http://" + args.uri + ":" + args.port.toString();
} else {
// Assign the Default Setting for the Channel.
args.params = layerDefaultParameters[args.channel];
}
// Define a Logger
const logger = getNopeLogger("Shutdown-CLI");
@ -101,8 +130,8 @@ export async function interact(
const dispatcher: nopeDispatcherManager = getDispatcher(
{
communicator: getLayer(
"io-client",
"http://" + args.uri + ":" + args.port.toString(),
args.channel,
args.params,
args.log
) as ICommunicationBridge,
logger: getNopeLogger("dispatcher", args.log)