Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 1 addition & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 1 addition & 7 deletions demos/api-client/main.ts
Original file line number Diff line number Diff line change
@@ -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)
9 changes: 1 addition & 8 deletions demos/data-transform/main.ts
Original file line number Diff line number Diff line change
@@ -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)
10 changes: 1 addition & 9 deletions demos/deploy-tool/main.ts
Original file line number Diff line number Diff line change
@@ -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' },
Expand Down Expand Up @@ -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 }) })
10 changes: 1 addition & 9 deletions demos/hello-world/main.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { command, defineManifest, run } from 'cti'
import type { Config } from 'cti'

const hello = command({
meta: { description: 'Greet someone' },
Expand All @@ -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 }) })
9 changes: 1 addition & 8 deletions demos/interactive-io/main.ts
Original file line number Diff line number Diff line change
@@ -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)
10 changes: 1 addition & 9 deletions demos/project-init/main.ts
Original file line number Diff line number Diff line change
@@ -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'

Expand Down Expand Up @@ -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 }) })
9 changes: 1 addition & 8 deletions demos/todo-app/main.ts
Original file line number Diff line number Diff line change
@@ -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)
14 changes: 6 additions & 8 deletions docs/getting-started/quickstart.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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' },
Expand All @@ -68,7 +66,7 @@ const hello: CommandModule = {
const greeting = ctx.flags.formal ? 'Greetings' : 'Hello'
ctx.io.write(`${greeting}, ${name}!`)
},
}
})
```

Run it:
Expand Down
8 changes: 2 additions & 6 deletions skills/build-with-cti/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -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' },
Expand All @@ -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`.)
Expand Down