Parse command line arguments
This commit is contained in:
parent
ef910ec402
commit
b7367f599c
2 changed files with 23 additions and 18 deletions
|
|
@ -1,16 +1 @@
|
||||||
/*
|
|
||||||
The level for the logger to display, can be one of the following:
|
|
||||||
"silly"
|
|
||||||
"debug"
|
|
||||||
"info"
|
|
||||||
"error"
|
|
||||||
"warn"
|
|
||||||
"fatal"
|
|
||||||
"trace"
|
|
||||||
defaults to "info"
|
|
||||||
*/
|
|
||||||
export const LOG_LEVEL: log_level = `silly`;
|
|
||||||
export const LOG_NAME: string = `Secret Hitler`;
|
export const LOG_NAME: string = `Secret Hitler`;
|
||||||
|
|
||||||
|
|
||||||
export const WSS_PORT: number = 3000;
|
|
||||||
24
src/main.ts
24
src/main.ts
|
|
@ -1,8 +1,10 @@
|
||||||
|
import arg from "arg";
|
||||||
import { Logger } from "tslog";
|
import { Logger } from "tslog";
|
||||||
import * as sio from "socket.io";
|
import * as sio from "socket.io";
|
||||||
import { writeFileSync } from "fs";
|
import { writeFileSync } from "fs";
|
||||||
import { Game } from "./utils/Game";
|
import { Game } from "./utils/Game";
|
||||||
import { Vote } from "./events/Vote";
|
import { Vote } from "./events/Vote";
|
||||||
|
import { LOG_NAME } from "./constants";
|
||||||
import { KillGame } from "./events/KillGame";
|
import { KillGame } from "./events/KillGame";
|
||||||
import { JoinGame } from "./events/JoinGame";
|
import { JoinGame } from "./events/JoinGame";
|
||||||
import { HostGame } from "./events/HostGame";
|
import { HostGame } from "./events/HostGame";
|
||||||
|
|
@ -18,14 +20,32 @@ import { ChancellorPolicy } from "./events/ChancellorPolicy";
|
||||||
import { PresidentPolicies } from "./events/PresidentPolicies";
|
import { PresidentPolicies } from "./events/PresidentPolicies";
|
||||||
import { ChancellorNomination } from "./events/ChancellorNomination";
|
import { ChancellorNomination } from "./events/ChancellorNomination";
|
||||||
import { ExecutiveConfirmation } from "./events/ExecutiveConfirmation";
|
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({
|
export var log: Logger = new Logger({
|
||||||
displayFunctionName: false,
|
displayFunctionName: false,
|
||||||
displayLoggerName: false,
|
displayLoggerName: false,
|
||||||
displayFilePath: `hidden`,
|
displayFilePath: `hidden`,
|
||||||
displayLogLevel: true,
|
displayLogLevel: true,
|
||||||
minLevel: LOG_LEVEL || `info`,
|
minLevel: LOG_LEVEL,
|
||||||
name: LOG_NAME,
|
name: LOG_NAME,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue