MCPcopy
hub / github.com/coder/mux / parseArgs

Function parseArgs

scripts/with-storybook.ts:56–96  ·  view source on GitHub ↗
(argv: string[])

Source from the content-addressed store, hash-verified

54}
55
56function parseArgs(argv: string[]): Options {
57 if (argv.includes("--help") || argv.includes("-h")) {
58 printHelp();
59 process.exit(0);
60 }
61
62 let port = parsePort(process.env.STORYBOOK_PORT ?? String(DEFAULT_PORT));
63 let timeoutMs = parsePositiveInteger(
64 process.env.STORYBOOK_TIMEOUT_MS ?? String(DEFAULT_TIMEOUT_MS),
65 "--timeout-ms"
66 );
67
68 const delimiterIndex = argv.indexOf("--");
69 const optionArgs = delimiterIndex === -1 ? [] : argv.slice(0, delimiterIndex);
70 const command = delimiterIndex === -1 ? argv : argv.slice(delimiterIndex + 1);
71 if (delimiterIndex === -1 && argv[0]?.startsWith("-")) {
72 throw new Error("Missing `-- <command>` delimiter. Run with --help for usage.");
73 }
74 if (command.length === 0) {
75 throw new Error("Missing command after `--`. Run with --help for usage.");
76 }
77
78 for (let index = 0; index < optionArgs.length; index += 1) {
79 const arg = optionArgs[index];
80 if (arg === "--port" || arg === "-p") {
81 const value = optionArgs[index + 1];
82 if (!value) throw new Error(`${arg} requires a value`);
83 port = parsePort(value);
84 index += 1;
85 } else if (arg === "--timeout-ms") {
86 const value = optionArgs[index + 1];
87 if (!value) throw new Error(`${arg} requires a value`);
88 timeoutMs = parsePositiveInteger(value, arg);
89 index += 1;
90 } else {
91 throw new Error(`Unknown option: ${arg}`);
92 }
93 }
94
95 return { port, timeoutMs, command };
96}
97
98function storybookUrl(port: number): string {
99 return `http://127.0.0.1:${port}`;

Callers 4

index.tsFile · 0.85
replay-history.tsFile · 0.85
mainFunction · 0.85

Calls 3

parsePortFunction · 0.85
printHelpFunction · 0.70
parsePositiveIntegerFunction · 0.70

Tested by

no test coverage detected