Skip to content

Commit 4800ca3

Browse files
committed
kebab case options
1 parent 7d213ce commit 4800ca3

File tree

3 files changed

+22
-19
lines changed

3 files changed

+22
-19
lines changed

Diff for: README.md

+8-5
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ Which could be invoked with any of:
167167

168168
#### Flags
169169

170-
`z.object(...)` inputs become flags (passed with `--foo bar` or `--foo=bar`) syntax. Values are accepted in either `--camelCase` or `--kebab-case`, and are parsed like in most CLI programs:
170+
`z.object(...)` inputs become flags (passed with `--foo bar` or `--foo=bar`) syntax. Values are accepted in `--kebab-case`, and are parsed like in most CLI programs:
171171

172172
Strings:
173173

@@ -198,6 +198,11 @@ Other types:
198198
- `z.object({ foo: z.object({ bar: z.number() }) })` will parse inputs as JSON:
199199
- `--foo '{"bar": 1}'` maps to `{foo: {bar: 1}}`
200200

201+
Multi-word flags:
202+
203+
- `z.object({ multiWord: z.string() })` will map:
204+
- `--multi-word foo` to `{multiWord: 'foo'}`
205+
201206
Unions and intersections should also work as expected, but make sure to test them thoroughly, especially if they are deeply-nested.
202207

203208
#### Both
@@ -642,20 +647,18 @@ In general, you should rely on `trpc-cli` to correctly handle the lifecycle and
642647

643648
## Features and Limitations
644649

645-
- Nested subrouters ([example](./test/fixtures//migrations.ts)) - command will be dot separated e.g. `search.byId`
650+
- Nested subrouters ([example](./test/fixtures/migrations.ts)) - procedures in nested routers will become subcommands will be dot separated e.g. `mycli search byId --id 123`
646651
- Middleware, `ctx`, multi-inputs work as normal
647652
- Return values are logged using `console.info` (can be configured to pass in a custom logger)
648653
- `process.exit(...)` called with either 0 or 1 depending on successful resolve
649654
- Help text shown on invalid inputs
650-
- Support kebab-case flag aliases
651-
- Support flag aliases via `alias` callback (see migrations example below)
655+
- Support flag aliases via `aliases` meta property (see migrations example below)
652656
- Union types work, but they should ideally be non-overlapping for best results
653657
- Limitation: Only zod types are supported right now
654658
- Limitation: Only object types are allowed as input. No positional arguments supported
655659
- If there's interest, this could be added in future for inputs of type `z.string()` or `z.tuple([z.string(), ...])`
656660
- Limitation: Nested-object input props must be passed as json
657661
- e.g. `z.object({ foo: z.object({ bar: z.number() }) }))` can be supplied via using `--foo '{"bar": 123}'`
658-
- If there's interest, support for `--foo.bar=1` could be added using [type-flag's dot-nested flags](https://github.com/privatenumber/type-flag?tab=readme-ov-file#dot-nested-flags) but edge cases/preprocessing needs proper consideration first.
659662
- Limitation: No `subscription` support.
660663
- In theory, this might be supportable via `@inquirer/prompts`. Proposals welcome!
661664

Diff for: test/e2e.test.ts

+11-11
Original file line numberDiff line numberDiff line change
@@ -380,13 +380,13 @@ test('fs copy', async () => {
380380
Usage: fs diff [options] <Base path> <Head path>
381381
382382
Arguments:
383-
Base path Base path (required)
384-
Head path Head path (required)
383+
Base path Base path (required)
384+
Head path Head path (required)
385385
386386
Options:
387-
--ignoreWhitespace [boolean] Ignore whitespace changes (default: false)
388-
--trim [boolean] Trim start/end whitespace (default: false)
389-
-h, --help display help for command
387+
--ignore-whitespace [boolean] Ignore whitespace changes (default: false)
388+
--trim [boolean] Trim start/end whitespace (default: false)
389+
-h, --help display help for command
390390
"
391391
`)
392392
})
@@ -396,20 +396,20 @@ test('fs diff', async () => {
396396
"Usage: fs diff [options] <Base path> <Head path>
397397
398398
Arguments:
399-
Base path Base path (required)
400-
Head path Head path (required)
399+
Base path Base path (required)
400+
Head path Head path (required)
401401
402402
Options:
403-
--ignoreWhitespace [boolean] Ignore whitespace changes (default: false)
404-
--trim [boolean] Trim start/end whitespace (default: false)
405-
-h, --help display help for command"
403+
--ignore-whitespace [boolean] Ignore whitespace changes (default: false)
404+
--trim [boolean] Trim start/end whitespace (default: false)
405+
-h, --help display help for command"
406406
`)
407407
expect(await tsx('fs', ['diff', 'one', 'two'])).toMatchInlineSnapshot(`""`)
408408
expect(await tsx('fs', ['diff', 'one', 'three'])).toMatchInlineSnapshot(
409409
`"base and head differ at index 0 ("a" !== "x")"`,
410410
)
411411
expect(await tsx('fs', ['diff', 'three', 'four'])).toMatchInlineSnapshot(`"base has length 5 and head has length 6"`)
412-
expect(await tsx('fs', ['diff', 'three', 'four', '--ignoreWhitespace'])).toMatchInlineSnapshot(`""`)
412+
expect(await tsx('fs', ['diff', 'three', 'four', '--ignore-whitespace'])).toMatchInlineSnapshot(`""`)
413413
})
414414

415415
test('thrown error in procedure includes call stack', async () => {

Diff for: test/zod-inputs.test.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -285,10 +285,10 @@ test('custom default procedure', async () => {
285285

286286
const params: TrpcCliParams<typeof yarn> = {router: yarn}
287287

288-
const yarnOutput = await runWith(params, ['--frozenLockfile'])
288+
const yarnOutput = await runWith(params, ['--frozen-lockfile'])
289289
expect(yarnOutput).toMatchInlineSnapshot(`"install: {"frozenLockfile":true}"`)
290290

291-
const yarnInstallOutput = await runWith(params, ['install', '--frozenLockfile'])
291+
const yarnInstallOutput = await runWith(params, ['install', '--frozen-lockfile'])
292292
expect(yarnInstallOutput).toMatchInlineSnapshot(`"install: {"frozenLockfile":true}"`)
293293
})
294294

@@ -302,7 +302,7 @@ test('command alias', async () => {
302302

303303
const params: TrpcCliParams<typeof yarn> = {router: yarn}
304304

305-
const yarnIOutput = await runWith(params, ['i', '--frozenLockfile'])
305+
const yarnIOutput = await runWith(params, ['i', '--frozen-lockfile'])
306306
expect(yarnIOutput).toMatchInlineSnapshot(`"install: {"frozenLockfile":true}"`)
307307
})
308308

0 commit comments

Comments
 (0)