Skip to content

Commit 6923262

Browse files
authored
chore: remove commander (#380)
1 parent 6070a1e commit 6923262

File tree

3 files changed

+58
-40
lines changed

3 files changed

+58
-40
lines changed

bin/smee.js

Lines changed: 58 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,70 @@
11
#!/usr/bin/env node
22

3-
import { program } from "commander";
3+
import { parseArgs } from "node:util";
44
import { readFile } from "node:fs/promises";
55
import Client from "../index.js";
66

77
const { version } = JSON.parse(
88
await readFile(new URL("../package.json", import.meta.url)),
99
);
1010

11-
program
12-
.version(version, "-v, --version")
13-
.usage("[options]")
14-
.option(
15-
"-u, --url <url>",
16-
"URL of the webhook proxy service. Default: https://smee.io/new",
17-
)
18-
.option(
19-
"-t, --target <target>",
20-
"Full URL (including protocol and path) of the target service the events will forwarded to. Default: http://127.0.0.1:PORT/PATH",
21-
)
22-
.option("-p, --port <n>", "Local HTTP server port", process.env.PORT || 3000)
23-
.option("-P, --path <path>", "URL path to post proxied requests to`", "/")
24-
.parse(process.argv);
25-
26-
const opts = program.opts();
27-
28-
const { target = `http://127.0.0.1:${opts.port}${opts.path}` } = opts;
29-
30-
async function setup() {
31-
let source = opts.url;
32-
33-
if (!source) {
34-
source = await Client.createChannel();
11+
const { values: options } = parseArgs({
12+
options: {
13+
version: {
14+
type: "boolean",
15+
short: "v",
16+
default: false,
17+
},
18+
help: {
19+
type: "boolean",
20+
short: "h",
21+
default: false,
22+
},
23+
url: {
24+
type: "string",
25+
short: "u",
26+
default: "https://smee.io/new",
27+
},
28+
target: {
29+
type: "string",
30+
short: "t",
31+
},
32+
path: {
33+
type: "string",
34+
short: "P",
35+
default: "/",
36+
},
37+
port: {
38+
type: "string",
39+
short: "p",
40+
default: process.env.PORT || "3000",
41+
},
42+
},
43+
});
44+
45+
if (options.help) {
46+
console.log(`Usage: smee [options]
47+
48+
Options:
49+
-v, --version Display the version number
50+
-u, --url <url> URL of the webhook proxy service. Default: https://smee.io/new
51+
-t, --target <target> Full URL (including protocol and path) of the target service the events will forwarded to.
52+
Default: http://127.0.0.1:PORT/PATH
53+
-p, --port <n> Local HTTP server port. Default: 3000
54+
-P, --path <path> URL path to post proxied requests to. Default: "/"
55+
-h, --help Display this help message`);
56+
} else if (options.version) {
57+
console.log(version);
58+
} else {
59+
const { target = `http://127.0.0.1:${options.port}${options.path}` } =
60+
options;
61+
62+
async function setup() {
63+
const source = options.url ?? (await Client.createChannel());
64+
65+
const client = new Client({ source, target });
66+
client.start();
3567
}
3668

37-
const client = new Client({ source, target });
38-
client.start();
69+
setup();
3970
}
40-
41-
setup();

package-lock.json

Lines changed: 0 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
"author": "",
2828
"license": "ISC",
2929
"dependencies": {
30-
"commander": "^12.0.0",
3130
"eventsource": "^4.0.0",
3231
"undici": "^7.0.0",
3332
"validator": "^13.11.0"

0 commit comments

Comments
 (0)