summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEuAndreh <eu@euandre.org>2024-03-01 16:04:29 -0300
committerEuAndreh <eu@euandre.org>2024-03-01 16:04:29 -0300
commit1e1127b52844bf4e2789658b8d40a15ca7e5fcda (patch)
tree07626a74a4c200ff5a25493bba1231b7209e6633
parentsrc/utils.mjs: Remove eq(), use utils.isDeepStrictEqual from "node:utils" ins... (diff)
downloadpapod-1e1127b52844bf4e2789658b8d40a15ca7e5fcda.tar.gz
papod-1e1127b52844bf4e2789658b8d40a15ca7e5fcda.tar.xz
src/api.mjs: Simplify handling of arguments
-rw-r--r--src/api.mjs27
-rwxr-xr-xtests/cli-opts.sh2
2 files changed, 12 insertions, 17 deletions
diff --git a/src/api.mjs b/src/api.mjs
index fb62adc..31bb09e 100644
--- a/src/api.mjs
+++ b/src/api.mjs
@@ -3,23 +3,18 @@ import process from "node:process";
import * as ircd from "./ircd.mjs";
import * as web from "./web.mjs";
-export const main = async () => {
- if (process.argv.length === 3 && process.argv[2] === "-V") {
- console.log("papo 1970-01-01 0.1.0");
- return;
- }
-
- if (process.argv[2] === "ircd") {
- await ircd.app(process.argv[3]);
- return;
- }
+const SUBCOMMANDS = {
+ ircd: ircd.app,
+ web: web.app,
+};
- if (process.argv[2] === "web") {
- await web.app(process.argv[3]);
- return;
+export const main = async () => {
+ const [_node, _file, cmdName, ...args] = process.argv;
+ const cmd = SUBCOMMANDS[cmdName];
+ if (cmd === undefined) {
+ console.error("Usage: papo SUBCOMMAND [OPTIONS]");
+ return process.exit(2);
}
- console.log({
- argv: process.argv,
- });
+ await cmd(...args);
};
diff --git a/tests/cli-opts.sh b/tests/cli-opts.sh
index b67ab11..fcb62ca 100755
--- a/tests/cli-opts.sh
+++ b/tests/cli-opts.sh
@@ -1,4 +1,4 @@
#!/bin/sh
set -eu
-"$@" -V >&2
+exit