Parse command line arguments

This commit is contained in:
Oliver-Akins 2020-10-22 20:35:10 -06:00
parent ef910ec402
commit b7367f599c
2 changed files with 23 additions and 18 deletions

View file

@ -1,8 +1,10 @@
import arg from "arg";
import { Logger } from "tslog";
import * as sio from "socket.io";
import { writeFileSync } from "fs";
import { Game } from "./utils/Game";
import { Vote } from "./events/Vote";
import { LOG_NAME } from "./constants";
import { KillGame } from "./events/KillGame";
import { JoinGame } from "./events/JoinGame";
import { HostGame } from "./events/HostGame";
@ -18,14 +20,32 @@ import { ChancellorPolicy } from "./events/ChancellorPolicy";
import { PresidentPolicies } from "./events/PresidentPolicies";
import { ChancellorNomination } from "./events/ChancellorNomination";
import { ExecutiveConfirmation } from "./events/ExecutiveConfirmation";
import { LOG_LEVEL, LOG_NAME, WSS_PORT } from "./constants";
// Argument parsing
const args = arg({
"--port": Number,
"--log": String,
// Aliases
"-l": "--log",
"-p": "--port",
"--level": "--log"
});
const LOG_LEVEL: log_level = args["--log"] as log_level || `info`;
const WSS_PORT = args["--port"] || 3000;
// Ensure the log level is valid
if (![`silly`,`debug`,`info`,`error`,`warn`,`fatal`,`trace`].includes(LOG_LEVEL)) {
throw new Error(`Invalid log level: ${LOG_LEVEL}`)
}
export var log: Logger = new Logger({
displayFunctionName: false,
displayLoggerName: false,
displayFilePath: `hidden`,
displayLogLevel: true,
minLevel: LOG_LEVEL || `info`,
minLevel: LOG_LEVEL,
name: LOG_NAME,
});