diff --git a/README.md b/README.md index 7445e16..d673a53 100644 --- a/README.md +++ b/README.md @@ -73,14 +73,8 @@ Create `main.ts`: ```typescript import { run } from 'cti' -import type { Config } from 'cti' -const config: Config = { - name: 'new-cli', - version: '1.0.0', -} - -void run(config, import.meta) +void run({ name: 'new-cli', version: '1.0.0' }, import.meta) ``` That's the whole entrypoint, and it's the last time you'll edit it. CTI automatically diff --git a/demos/api-client/main.ts b/demos/api-client/main.ts index e05f78f..dd62b81 100644 --- a/demos/api-client/main.ts +++ b/demos/api-client/main.ts @@ -1,9 +1,3 @@ import { run } from 'cti' -import type { Config } from 'cti' -const config: Config = { - name: 'api-client', - version: '1.0.0', -} - -void run(config, import.meta) +void run({ name: 'api-client', version: '1.0.0' }, import.meta) diff --git a/demos/data-transform/main.ts b/demos/data-transform/main.ts index b7ae138..e70a2b2 100644 --- a/demos/data-transform/main.ts +++ b/demos/data-transform/main.ts @@ -1,10 +1,3 @@ import { run } from 'cti' -import type { Config } from 'cti' -const config: Config = { - name: 'data-transform', - bin: 'transform', - version: '1.0.0', -} - -void run(config, import.meta) +void run({ name: 'data-transform', bin: 'transform', version: '1.0.0' }, import.meta) diff --git a/demos/deploy-tool/main.ts b/demos/deploy-tool/main.ts index 1452e5d..26442d8 100644 --- a/demos/deploy-tool/main.ts +++ b/demos/deploy-tool/main.ts @@ -1,5 +1,4 @@ import { command, defineManifest, run } from 'cti' -import type { Config } from 'cti' const deploy = command({ meta: { description: 'Deploy application to an environment' }, @@ -55,11 +54,4 @@ const status = command({ }, }) -const config: Config = { - name: 'deploy-tool', - bin: 'deploy', - version: '1.0.0', - manifest: defineManifest({ deploy, rollback, status }), -} - -void run(config) +void run({ name: 'deploy-tool', bin: 'deploy', version: '1.0.0', manifest: defineManifest({ deploy, rollback, status }) }) diff --git a/demos/hello-world/main.ts b/demos/hello-world/main.ts index d2273da..25768b3 100644 --- a/demos/hello-world/main.ts +++ b/demos/hello-world/main.ts @@ -1,5 +1,4 @@ import { command, defineManifest, run } from 'cti' -import type { Config } from 'cti' const hello = command({ meta: { description: 'Greet someone' }, @@ -17,11 +16,4 @@ const goodbye = command({ }, }) -const config: Config = { - name: 'hello-world', - bin: 'hello', - version: '1.0.0', - manifest: defineManifest({ hello, goodbye }), -} - -void run(config) +void run({ name: 'hello-world', bin: 'hello', version: '1.0.0', manifest: defineManifest({ hello, goodbye }) }) diff --git a/demos/interactive-io/main.ts b/demos/interactive-io/main.ts index d6379f2..2c495ba 100644 --- a/demos/interactive-io/main.ts +++ b/demos/interactive-io/main.ts @@ -1,10 +1,3 @@ import { run } from 'cti' -import type { Config } from 'cti' -const config: Config = { - name: 'interactive-io', - bin: 'profiles', - version: '1.0.0', -} - -void run(config, import.meta) +void run({ name: 'interactive-io', bin: 'profiles', version: '1.0.0' }, import.meta) diff --git a/demos/project-init/main.ts b/demos/project-init/main.ts index 7805e5b..d654d49 100644 --- a/demos/project-init/main.ts +++ b/demos/project-init/main.ts @@ -1,5 +1,4 @@ import { command, defineManifest, run } from 'cti' -import type { Config } from 'cti' import { mkdirSync, writeFileSync } from 'node:fs' import { join } from 'node:path' @@ -46,11 +45,4 @@ const init = command({ }, }) -const config: Config = { - name: 'project-init', - bin: 'init', - version: '1.0.0', - manifest: defineManifest({ init }), -} - -void run(config) +void run({ name: 'project-init', bin: 'init', version: '1.0.0', manifest: defineManifest({ init }) }) diff --git a/demos/todo-app/main.ts b/demos/todo-app/main.ts index 058c08e..ae504d1 100644 --- a/demos/todo-app/main.ts +++ b/demos/todo-app/main.ts @@ -1,10 +1,3 @@ import { run } from 'cti' -import type { Config } from 'cti' -const config: Config = { - name: 'todo-app', - bin: 'todo', - version: '1.0.0', -} - -void run(config, import.meta) +void run({ name: 'todo-app', bin: 'todo', version: '1.0.0' }, import.meta) diff --git a/docs/getting-started/quickstart.md b/docs/getting-started/quickstart.md index 5b702c3..d3ae947 100644 --- a/docs/getting-started/quickstart.md +++ b/docs/getting-started/quickstart.md @@ -30,20 +30,18 @@ bun install Create `main.ts`. A command is a `CommandModule`; you map commands to routes with `defineManifest`, then dispatch with `run`: ```typescript -import type { CommandModule } from './types/command' -import type { Config } from './types/config' +import { command } from './core/command' import { defineManifest, run } from './core/runtime' -const hello: CommandModule = { +const hello = command({ meta: { description: 'Greet someone' }, run(ctx) { const name = ctx.positionals[0] ?? 'World' ctx.io.write(`Hello, ${name}!`) }, -} +}) -const config: Config = { name: 'my-cli', version: '1.0.0', manifest: defineManifest({ hello }) } -void run(config) +void run({ name: 'my-cli', version: '1.0.0', manifest: defineManifest({ hello }) }) ``` ### Run It @@ -58,7 +56,7 @@ bun run ./main.ts hello Alice Declare flags on the command; `run` parses and coerces them into `ctx.flags`: ```typescript -const hello: CommandModule = { +const hello = command({ meta: { description: 'Greet someone' }, flags: { formal: { type: 'boolean', short: 'f', description: 'Use a formal greeting' }, @@ -68,7 +66,7 @@ const hello: CommandModule = { const greeting = ctx.flags.formal ? 'Greetings' : 'Hello' ctx.io.write(`${greeting}, ${name}!`) }, -} +}) ``` Run it: diff --git a/skills/build-with-cti/SKILL.md b/skills/build-with-cti/SKILL.md index 6e22252..f3db8c0 100644 --- a/skills/build-with-cti/SKILL.md +++ b/skills/build-with-cti/SKILL.md @@ -57,7 +57,6 @@ Inline manifest (small CLI): ```typescript import { command, defineManifest, run } from 'cti' -import type { Config } from 'cti' const hello = command({ meta: { description: 'Greet someone' }, @@ -66,18 +65,15 @@ const hello = command({ }, }) -const config: Config = { name: 'my-cli', version: '1.0.0', manifest: defineManifest({ hello }) } -void run(config) +void run({ name: 'my-cli', version: '1.0.0', manifest: defineManifest({ hello }) }) ``` Directory-scanned manifest (larger CLI) — pass `import.meta` and let `run()` discover commands from `config.commandsDir`: ```typescript import { run } from 'cti' -import type { Config } from 'cti' -const config: Config = { name: 'my-cli', commandsDir: 'commands', version: '1.0.0' } -void run(config, import.meta) +void run({ name: 'my-cli', commandsDir: 'commands', version: '1.0.0' }, import.meta) ``` (You can also call `discoverManifest(commandsDir)` yourself and assign the result to `config.manifest` — useful if you want to inspect or modify entries before dispatch. Either way, `Manifest` ends up on `config.manifest`.)