From 07c9cdebb69d3287bbc3891554490a2fb3026cff Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Wed, 1 Dec 2021 10:44:03 +0100 Subject: [PATCH] Add usage message to development server --- README.md | 2 ++ dev-server.js | 23 ++++++++++++++++++++--- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 5d2a6e8..a617b91 100644 --- a/README.md +++ b/README.md @@ -67,6 +67,8 @@ can be used. For instance, to run gamja on Libera Chat: npm install --include=dev npm start -- irc.libera.chat +See `npm start -- -h` for a list of options. + ### Production build Optionally, [Parcel] can be used to build a minified version of gamja. diff --git a/dev-server.js b/dev-server.js index 2d23822..3c1b1f7 100644 --- a/dev-server.js +++ b/dev-server.js @@ -6,14 +6,31 @@ import { WebSocketServer } from "ws"; const WS_BAD_GATEWAY = 1014; +const usage = `usage: [options...] [host] + +Starts an HTTP server delivering static files. If [host] is specified, the +server will proxy WebSocket connections to the specified remote IRC server. + +Options: + -p Listening port (default: 8080) + -h Show help message +`; + let localPort = 8080; let remoteHost; let remotePort = 6697; let args = process.argv.slice(2); -if (args[0] === "-p") { - localPort = parseInt(args[1], 10); - args = args.slice(2); +while (args.length > 0 && args[0].startsWith("-")) { + switch (args[0]) { + case "-p": + localPort = parseInt(args[1], 10); + args = args.slice(2); + break; + default: + console.log(usage); + process.exit(args[0] === "-h" ? 0 : 1); + } } remoteHost = args[0];