Skip to content

Commit

Permalink
feat: change input fn
Browse files Browse the repository at this point in the history
  • Loading branch information
k2on committed Oct 26, 2024
1 parent efcc422 commit 164c865
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 10 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ const cli = router({
module: command()
.describe("Add a module")
.input(z.object({ name: z.number() }))
.fn(({ name }) => {
console.log(`Adding module: "${name}`);
.fn(({ input }) => {
console.log(`Adding module: "${input.name}`);
}),
}),
version: command()
Expand Down
4 changes: 2 additions & 2 deletions examples/basic/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ const cli = router({
module: command()
.describe("Add a module")
.input(z.object({ name: z.number() }))
.fn(({ name }) => {
console.log(`Adding module: "${name}`);
.fn(({ input }) => {
console.log(`Adding module: "${input.name}`);
}),
}),
version: command()
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ const cli = router({
module: command()
.describe("Add a module")
.input(z.object({ name: z.number() }))
.fn(({ name }) => {
console.log(`Adding module: "${name}`);
.fn(({ input }) => {
console.log(`Adding module: "${input.name}`);
}),
}),
version: command()
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@koons/cli",
"version": "0.1.1",
"version": "0.1.2",
"main": "./dist/index.js",
"module": "./dist/index.mjs",
"types": "./dist/index.d.ts",
Expand Down
6 changes: 3 additions & 3 deletions packages/cli/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class CommandBuilder<T extends ZodSchema> {
return new CommandBuilder<z.infer<typeof schema>>(this);
}

fn(fn: (input: T) => void): BuildCommand<any> {
fn(fn: (input: { input: T }) => void): BuildCommand<any> {
return {
_type: "command",
input: this.schema,
Expand All @@ -41,7 +41,7 @@ interface BuildCommand<T extends ZodTypeAny> {
_type: "command";
input?: ZodSchema<T>;
description?: string;
fn: (input: T) => void;
fn: (input: { input: T }) => void;
}

export type Commands = {
Expand Down Expand Up @@ -77,7 +77,7 @@ function next(input: CLI, current: string | undefined, args: string[]) {
{} as Record<string, unknown>,
);

handler.fn(obj);
handler.fn({ input: obj });
return;
} else {
const nextArg = args[1];
Expand Down

0 comments on commit 164c865

Please sign in to comment.