Skip to content

Commit eeab7ff

Browse files
matej21claude
andcommitted
refactor: replace custom arg parser with node:util parseArgs
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 70078cf commit eeab7ff

File tree

3 files changed

+32
-77
lines changed

3 files changed

+32
-77
lines changed

src/commands/input.ts

Lines changed: 32 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,39 @@
1-
import { parseArgs } from './utils/args'
1+
import { parseArgs } from 'node:util'
22

3-
const requireString = (value: string | boolean | undefined, name: string): string => {
4-
if (typeof value === 'string') {
5-
return value
3+
export const input = (() => {
4+
const { values, positionals } = parseArgs({
5+
args: process.argv.slice(2),
6+
allowPositionals: true,
7+
options: {
8+
env: { type: 'string' },
9+
'state-namespace': { type: 'string' },
10+
'account-id': { type: 'string' },
11+
'api-token': { type: 'string' },
12+
'dry-run': { type: 'boolean' },
13+
remote: { type: 'boolean' },
14+
destroy: { type: 'boolean' },
15+
validate: { type: 'boolean' },
16+
'out-state': { type: 'string' },
17+
},
18+
})
19+
20+
const main = positionals[0]
21+
if (!main) {
22+
console.error('Missing config entrypoint argument')
23+
process.exit(1)
624
}
7-
throw new Error(`Missing required string argument: ${name}`)
8-
}
925

10-
export const input = (() => {
11-
const { named, positional } = parseArgs(process.argv.slice(2))
1226
return {
13-
main: requireString(positional[0], 'config entrypoint'),
14-
env: requireString(named.env || process.env.CLOUDFLARE_ENV || 'local', 'environment'),
15-
stateNamespace: requireString(named['state-namespace'] || 'cf-state', 'state namespace'),
16-
accountId: (named['account-id'] || process.env.CLOUDFLARE_ACCOUNT_ID || '') as string,
17-
apiToken: (named['api-token'] || process.env.CLOUDFLARE_API_TOKEN || '') as string,
18-
dryRun: !!named['dry-run'],
19-
remote: !!named.remote,
20-
destroy: !!named.destroy,
21-
validate: !!named.validate,
22-
outStatePath: named['out-state'] === true ? 'out-state.json' : named['out-state'],
27+
main,
28+
env: values.env || process.env.CLOUDFLARE_ENV || 'local',
29+
stateNamespace: values['state-namespace'] || 'cf-state',
30+
accountId: values['account-id'] || process.env.CLOUDFLARE_ACCOUNT_ID || '',
31+
apiToken: values['api-token'] || process.env.CLOUDFLARE_API_TOKEN || '',
32+
dryRun: values['dry-run'] ?? false,
33+
remote: values.remote ?? false,
34+
destroy: values.destroy ?? false,
35+
validate: values.validate ?? false,
36+
outStatePath: values['out-state'],
2337
}
2438
})()
2539

src/commands/utils/args.ts

Lines changed: 0 additions & 20 deletions
This file was deleted.

tests/utils/args.test.ts

Lines changed: 0 additions & 39 deletions
This file was deleted.

0 commit comments

Comments
 (0)