Skip to content

Commit 360e164

Browse files
committed
Support arg typing via command helper
1 parent f3cd80a commit 360e164

File tree

4 files changed

+18
-2
lines changed

4 files changed

+18
-2
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-23] [Support arg typing via command helper](https://github.com/RubricLab/cli/commit/01730221c250dc651a1cc466ff3aef85a4361a1e)
12
- [2025-04-23] [Trigger build](https://github.com/RubricLab/cli/commit/f48dfb50b8388ca5b9a6762aba521093a8226e5b)
23
- [2025-04-14] [src -> lib](https://github.com/RubricLab/cli/commit/5366d58c027c275252ef7e79f20afd61183949c6)
34
- [2025-04-14] [publish lib/index](https://github.com/RubricLab/cli/commit/77d2c126ff9cf6ec9bcbff925d79bcda2b187da6)

lib/index.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { parseCommand } from './parse'
22
import type { CLI, Command } from './types'
33
export { format } from './colors'
4+
import type { z } from 'zod'
45
export type { Command, CLI }
56

67
export function createCLI(config: {
@@ -21,3 +22,17 @@ export function createCLI(config: {
2122
}
2223
}
2324
}
25+
26+
export function createCommand<T extends z.ZodSchema>(config: {
27+
name: string
28+
description: string
29+
args: T
30+
handler: (args: z.infer<T>) => void | Promise<void>
31+
}): Command {
32+
return {
33+
name: config.name,
34+
description: config.description,
35+
args: config.args,
36+
handler: config.handler
37+
}
38+
}

lib/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { z } from 'zod'
22

3-
export type Command<TArgs extends z.ZodType = z.AnyZodObject> = {
3+
export type Command<TArgs extends z.ZodSchema = z.ZodSchema> = {
44
name: string
55
description: string
66
args: TArgs

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.5",
11+
"version": "0.0.6",
1212
"main": "lib/index.ts",
1313
"private": false,
1414
"dependencies": {

0 commit comments

Comments
 (0)