Skip to content

Commit 84e592d

Browse files
committed
Replace parseArgs with custom implementation
Implements a simplified parseArgs function inline to eliminate dependency on node:util parseArgs, supporting basic boolean and string options needed by the script.
1 parent 3790ce8 commit 84e592d

File tree

1 file changed

+46
-1
lines changed

1 file changed

+46
-1
lines changed

scripts/claude.mjs

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import { spawn } from 'node:child_process'
88
import { existsSync, promises as fs } from 'node:fs'
99
import path from 'node:path'
1010
import { fileURLToPath } from 'node:url'
11-
import { parseArgs } from 'node:util'
1211

1312
import colors from 'yoctocolors-cjs'
1413

@@ -18,6 +17,52 @@ const parentPath = path.join(rootPath, '..')
1817
const claudeDir = path.join(rootPath, '.claude')
1918
const WIN32 = process.platform === 'win32'
2019

20+
/**
21+
* Simplified parseArgs implementation for claude.mjs.
22+
* Handles basic boolean and string options without external dependencies.
23+
*/
24+
function parseArgs(config) {
25+
const { options = {}, args = process.argv.slice(2) } = config
26+
const values = {}
27+
const positionals = []
28+
29+
// Initialize defaults.
30+
for (const [key, opt] of Object.entries(options)) {
31+
if (opt.default !== undefined) {
32+
values[key] = opt.default
33+
}
34+
}
35+
36+
// Parse arguments.
37+
for (let i = 0; i < args.length; i++) {
38+
const arg = args[i]
39+
40+
if (arg === '--') {
41+
// Everything after -- is positional.
42+
positionals.push(...args.slice(i + 1))
43+
break
44+
}
45+
46+
if (arg.startsWith('--')) {
47+
const key = arg.slice(2)
48+
const opt = options[key]
49+
50+
if (opt) {
51+
if (opt.type === 'boolean') {
52+
values[key] = true
53+
} else if (opt.type === 'string') {
54+
values[key] = args[++i]
55+
}
56+
}
57+
} else if (!arg.startsWith('-')) {
58+
// Positional argument.
59+
positionals.push(arg)
60+
}
61+
}
62+
63+
return { positionals, values }
64+
}
65+
2166
// Socket project names.
2267
const SOCKET_PROJECTS = [
2368
'socket-cli',

0 commit comments

Comments
 (0)