Skip to content

Commit ec3bf12

Browse files
committed
Handle undefined args
1 parent 360e164 commit ec3bf12

File tree

3 files changed

+6
-5
lines changed

3 files changed

+6
-5
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
- [2025-04-24] [Handle undefined args](https://github.com/RubricLab/cli/commit/f34a9b004438071586bdd126db88a84ab8f1b9b2)
12
- [2025-04-23] [Support arg typing via command helper](https://github.com/RubricLab/cli/commit/01730221c250dc651a1cc466ff3aef85a4361a1e)
23
- [2025-04-23] [Trigger build](https://github.com/RubricLab/cli/commit/f48dfb50b8388ca5b9a6762aba521093a8226e5b)
34
- [2025-04-14] [src -> lib](https://github.com/RubricLab/cli/commit/5366d58c027c275252ef7e79f20afd61183949c6)

lib/parse.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export async function parseCommand({
2020
}
2121

2222
if (argv[0] === '--help' || argv[0] === '-h') {
23-
showHelp({ commands, cliName, command: argv[1] })
23+
showHelp({ commands, cliName, command: argv[1] || '' })
2424
return
2525
}
2626

@@ -70,11 +70,11 @@ function parseArgs<T extends z.ZodType>({
7070
str.replace(/-([a-z])/g, (_, letter) => letter.toUpperCase())
7171

7272
for (let i = 0; i < argv.length; i++) {
73-
const arg = argv[i]
73+
const arg = argv[i] || ''
7474

7575
const flagMatch = arg.match(flagRegex)
7676
if (flagMatch) {
77-
const flagName = kebabToCamel(flagMatch[1])
77+
const flagName = kebabToCamel(flagMatch[1] || '')
7878

7979
const nextArg = argv[i + 1]
8080
const nextIsValue = nextArg && !nextArg.startsWith('-')
@@ -105,7 +105,7 @@ function parseArgs<T extends z.ZodType>({
105105

106106
const shortMatch = arg.match(shortFlagRegex)
107107
if (shortMatch) {
108-
const flags = shortMatch[1].split('')
108+
const flags = (shortMatch[1] || '').split('')
109109
for (const flag of flags) {
110110
if (schema instanceof z.ZodObject) {
111111
const shape = schema.shape

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"lint:fix": "bun x biome lint . --write --unsafe"
99
},
1010
"name": "@rubriclab/cli",
11-
"version": "0.0.6",
11+
"version": "0.0.7",
1212
"main": "lib/index.ts",
1313
"private": false,
1414
"dependencies": {

0 commit comments

Comments
 (0)