argsbarg 1.4.2 → 1.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.private/scratch.md +2 -1
- package/CHANGELOG.md +29 -1
- package/README.md +22 -7
- package/docs/ai-skills.md +47 -0
- package/docs/install.md +84 -0
- package/docs/mcp.md +7 -5
- package/index.d.ts +11 -9
- package/package.json +1 -1
- package/src/builtins/builtins.test.ts +101 -0
- package/src/builtins/completion-bash.ts +240 -0
- package/src/builtins/completion-fish.ts +73 -0
- package/src/builtins/completion-group.ts +50 -0
- package/src/builtins/completion-zsh.ts +244 -0
- package/src/builtins/dispatch.ts +123 -0
- package/src/builtins/export.ts +46 -0
- package/src/builtins/index.ts +10 -0
- package/src/builtins/install.ts +99 -0
- package/src/builtins/mcp.ts +13 -0
- package/src/builtins/presentation.ts +39 -0
- package/src/builtins/scopes.ts +45 -0
- package/src/builtins/shell-helpers.ts +24 -0
- package/src/completion.ts +10 -652
- package/src/index.test.ts +135 -4
- package/src/index.ts +1 -0
- package/src/install/binary.ts +82 -0
- package/src/install/compiled.ts +15 -0
- package/src/install/completions.ts +52 -0
- package/src/install/detect-installed.ts +67 -0
- package/src/install/index.ts +196 -0
- package/src/install/install.test.ts +124 -0
- package/src/install/mcp-config.ts +70 -0
- package/src/install/paths.ts +69 -0
- package/src/install/plan.ts +183 -0
- package/src/install/shell.ts +56 -0
- package/src/install/status.ts +63 -0
- package/src/install/uninstall.ts +111 -0
- package/src/mcp/tools.ts +1 -1
- package/src/runtime.ts +23 -66
- package/src/schema.ts +7 -49
- package/src/skill/generate.ts +183 -0
- package/src/skill/install.ts +47 -0
- package/src/types.ts +12 -0
- package/src/validate.ts +14 -20
package/.private/scratch.md
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
- [x] --schema feature for ai agents
|
|
1
|
+
- [x] --schema feature for ai agents
|
|
2
|
+
- [x] opt-out install feature?
|
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,32 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [1.5.0] - 2026-06-20
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
|
|
14
|
+
- **`install` built-in** (compiled binaries only) — install binary, bash/zsh/fish completions, Cursor/Claude skills, and MCP config (`install --all --yes`, `--update`, `--status`, `--uninstall`).
|
|
15
|
+
- **`completion fish`** — fish tab-completion script generation.
|
|
16
|
+
- Root **`install`** config (`{ enabled?: boolean, prefix?: string }`).
|
|
17
|
+
|
|
18
|
+
### Changed (breaking)
|
|
19
|
+
|
|
20
|
+
- **Removed `ai` command group** — no more `ai mcp` or `ai skill`.
|
|
21
|
+
- **Restored top-level `mcp`** — `myapp mcp` (reserved only when `mcpServer` is set).
|
|
22
|
+
- **Removed `aiSkill` config** — skill directory name defaults to sanitized root `key`; use `install --skill` instead of `ai skill`.
|
|
23
|
+
|
|
24
|
+
## [1.4.3] - 2026-06-19
|
|
25
|
+
|
|
26
|
+
### Added
|
|
27
|
+
|
|
28
|
+
- **`ai` built-in group** — `myapp ai skill cursor` and `myapp ai skill claude` install Agent Skills (`SKILL.md` + `reference.md`) to project or global skill directories.
|
|
29
|
+
- **`aiSkill`** root config to opt out of skill install (`{ enabled: false }`).
|
|
30
|
+
|
|
31
|
+
### Changed (breaking)
|
|
32
|
+
|
|
33
|
+
- **`myapp mcp`** → **`myapp ai mcp`**
|
|
34
|
+
- Reserved top-level command **`mcp`** → **`ai`** (user commands may now be named `mcp`)
|
|
35
|
+
|
|
10
36
|
## [1.4.2] - 2026-06-19
|
|
11
37
|
|
|
12
38
|
### Added
|
|
@@ -123,7 +149,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
123
149
|
- Migrate schemas: rename every `children` property to **`commands`**; move positional definitions to **`CliPositional`** objects on `positionals` and strip `positional` / `argMin` / `argMax` from flag definitions under `options` (flags only carry `name`, `description`, `kind`, and optional `shortName`).
|
|
124
150
|
- Imports: use `CliPositional` where needed; replace `CliOptionDef` with `CliOption` or `CliPositional` as appropriate.
|
|
125
151
|
|
|
126
|
-
[Unreleased]: https://github.com/bdombro/bun-argsbarg/compare/v1.
|
|
152
|
+
[Unreleased]: https://github.com/bdombro/bun-argsbarg/compare/v1.5.0...HEAD
|
|
153
|
+
[1.5.0]: https://github.com/bdombro/bun-argsbarg/releases/tag/v1.5.0
|
|
154
|
+
[1.4.3]: https://github.com/bdombro/bun-argsbarg/releases/tag/v1.4.3
|
|
127
155
|
[1.4.2]: https://github.com/bdombro/bun-argsbarg/releases/tag/v1.4.2
|
|
128
156
|
[1.4.1]: https://github.com/bdombro/bun-argsbarg/releases/tag/v1.4.1
|
|
129
157
|
[1.4.0]: https://github.com/bdombro/bun-argsbarg/releases/tag/v1.4.0
|
package/README.md
CHANGED
|
@@ -14,9 +14,9 @@ Why another CLI parser?
|
|
|
14
14
|
|
|
15
15
|
*Beautiful `-h` screens* — scoped help at any routing depth, rendered in rounded UTF-8 boxes with tables, terminal-width wrapping, and color when stdout is a TTY. Errors print in red with contextual help on stderr.
|
|
16
16
|
|
|
17
|
-
*Shell completions* — `completion bash` and `completion
|
|
17
|
+
*Shell completions* — `completion bash`, `completion zsh`, and `completion fish` built-ins generate installable scripts from your schema so users get tab completion for commands, flags, and positionals without extra tooling.
|
|
18
18
|
|
|
19
|
-
*Optional MCP server* — set `mcpServer: {}` on the program root to expose leaf commands as MCP tools and the full CLI tree as a schema resource (`myapp mcp` over stdio). See [docs/mcp.md](docs/mcp.md).
|
|
19
|
+
*Optional MCP server* — set `mcpServer: {}` on the program root to expose leaf commands as MCP tools and the full CLI tree as a schema resource (`myapp mcp` over stdio). See [docs/mcp.md](docs/mcp.md). Compiled binaries can install binary, completions, skills, and MCP config with `myapp install` — see [docs/install.md](docs/install.md).
|
|
20
20
|
|
|
21
21
|
*Bun-optimized* — built from the ground up for Bun and TypeScript, leveraging Bun’s performance and modern JavaScript features without any extra dependencies.
|
|
22
22
|
|
|
@@ -95,11 +95,12 @@ Every app gets:
|
|
|
95
95
|
|
|
96
96
|
- `-h` / `--help` at any routing depth (scoped help).
|
|
97
97
|
- **`--schema`** at the program root — print the full command tree as JSON (for tooling and agents).
|
|
98
|
-
- **`completion bash` / `completion zsh`** — print shell completion scripts to stdout (injected by `cliRun`).
|
|
99
|
-
- **`mcp`** — when `mcpServer
|
|
98
|
+
- **`completion bash` / `completion zsh` / `completion fish`** — print shell completion scripts to stdout (injected by `cliRun`).
|
|
99
|
+
- **`mcp`** — when `mcpServer` is set on the program root, run as an MCP stdio server (`myapp mcp`).
|
|
100
|
+
- **`install`** — when running as a compiled binary (`bun build --compile`), install the binary, completions, skills, and MCP config to the user environment (`myapp install --all --yes`). See [docs/install.md](docs/install.md).
|
|
100
101
|
|
|
101
|
-
Do not declare a top-level command named **`completion`** —
|
|
102
|
-
|
|
102
|
+
Do not declare a top-level command named **`completion`** or **`install`** — they are reserved.
|
|
103
|
+
When **`mcpServer`** is set, do not declare a top-level command named **`mcp`** — it is reserved for the MCP built-in.
|
|
103
104
|
Do not declare an option named **`schema`** — it is reserved for `--schema`.
|
|
104
105
|
|
|
105
106
|
|
|
@@ -109,6 +110,18 @@ Opt in on the program root with `mcpServer: {}` (or `{ name, version, … }`), t
|
|
|
109
110
|
|
|
110
111
|
See **[docs/mcp.md](docs/mcp.md)** for configuration, env bootstrapping, custom resources, Cursor setup, and protocol details.
|
|
111
112
|
|
|
113
|
+
### Install (compiled binaries)
|
|
114
|
+
|
|
115
|
+
After `bun build --compile`, ship a self-contained binary and let users run:
|
|
116
|
+
|
|
117
|
+
```bash
|
|
118
|
+
myapp install --all --yes
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
This copies the binary to `~/.local/bin`, installs shell completions (bash/zsh/fish when each shell is on PATH), writes Cursor/Claude skills when agent directories exist, and merges MCP server entries into Cursor and Claude config files.
|
|
122
|
+
|
|
123
|
+
See **[docs/install.md](docs/install.md)** for `--update`, `--status`, `--uninstall`, and flags.
|
|
124
|
+
|
|
112
125
|
|
|
113
126
|
### Shell completions
|
|
114
127
|
|
|
@@ -119,6 +132,8 @@ myapp completion bash > ~/.bash_completion.d/myapp
|
|
|
119
132
|
myapp completion zsh > ~/.zsh/completions/_myapp
|
|
120
133
|
# then: fpath+=(~/.zsh/completions); autoload -Uz compinit && compinit
|
|
121
134
|
# or, for a one-off test in the current shell: eval "$(myapp completion zsh)"
|
|
135
|
+
|
|
136
|
+
myapp completion fish > ~/.config/fish/completions/myapp.fish
|
|
122
137
|
```
|
|
123
138
|
|
|
124
139
|
|
|
@@ -207,7 +222,7 @@ The package root (`argsbarg` / `src/index.ts`) exports the types and runtime you
|
|
|
207
222
|
| `cliInvoke(root, argv)` | Parse and dispatch without exiting; returns captured stdout/stderr. |
|
|
208
223
|
| `cliErrWithHelp(ctx, msg)` | Print error + scoped help on stderr, exit 1. |
|
|
209
224
|
|
|
210
|
-
Reserved
|
|
225
|
+
Reserved identifiers (validated at startup): root commands **`completion`**, **`install`**, and **`mcp`** (only when `mcpServer` is set).
|
|
211
226
|
|
|
212
227
|
---
|
|
213
228
|
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
# Agent skills
|
|
2
|
+
|
|
3
|
+
ArgsBarg can generate Cursor and Claude Code skill directories (`SKILL.md` + `reference.md`) from your CLI schema.
|
|
4
|
+
|
|
5
|
+
## Install via `install` (recommended)
|
|
6
|
+
|
|
7
|
+
In a **compiled binary**, install skills to the user environment:
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
myapp install --skill --yes
|
|
11
|
+
# or
|
|
12
|
+
myapp install --all --yes
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
Skills are written when the agent home exists:
|
|
16
|
+
|
|
17
|
+
- Cursor: `~/.cursor/skills/<dir>/` when `~/.cursor` exists
|
|
18
|
+
- Claude Code: `~/.claude/skills/<dir>/` when `~/.claude` exists
|
|
19
|
+
|
|
20
|
+
The skill directory name defaults to the sanitized program `key` (e.g. `minimal.ts` → `minimal_ts`).
|
|
21
|
+
|
|
22
|
+
Existing skill directories are removed and rewritten on each install.
|
|
23
|
+
|
|
24
|
+
## Programmatic install
|
|
25
|
+
|
|
26
|
+
```typescript
|
|
27
|
+
import { cliSkillInstall } from "argsbarg/skill/install"; // internal module
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
For library use, call `cliSkillInstall(root, "cursor" | "claude", { global: true, rimraf: true })` — it returns changed file paths.
|
|
31
|
+
|
|
32
|
+
## Generated content
|
|
33
|
+
|
|
34
|
+
- **`SKILL.md`** — YAML frontmatter, when-to-use guidance, command catalog, MCP setup hints
|
|
35
|
+
- **`reference.md`** — full `--schema` JSON export
|
|
36
|
+
|
|
37
|
+
## MCP vs skills
|
|
38
|
+
|
|
39
|
+
| Mechanism | Role |
|
|
40
|
+
| --- | --- |
|
|
41
|
+
| **`myapp mcp`** (requires `mcpServer`) | Runtime tool execution over MCP |
|
|
42
|
+
| **`myapp install --skill`** | Static discovery files for agents |
|
|
43
|
+
|
|
44
|
+
See also:
|
|
45
|
+
|
|
46
|
+
- [MCP server](mcp.md) — `mcpServer` config and `mcp` protocol
|
|
47
|
+
- [Install](install.md) — binary, completions, skills, and MCP config
|
package/docs/install.md
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
# Install command
|
|
2
|
+
|
|
3
|
+
The `install` built-in is available only in **compiled binaries** (`bun build --compile`). It is hidden from help, `--schema`, and shell completions when running via `bun run`.
|
|
4
|
+
|
|
5
|
+
## Quick start
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
# First-time setup
|
|
9
|
+
myapp install --all --yes
|
|
10
|
+
|
|
11
|
+
# Refresh after upgrading
|
|
12
|
+
myapp install --update
|
|
13
|
+
|
|
14
|
+
# See what is installed
|
|
15
|
+
myapp install --status
|
|
16
|
+
|
|
17
|
+
# Remove everything detected
|
|
18
|
+
myapp install --uninstall --yes
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## What gets installed
|
|
22
|
+
|
|
23
|
+
| Target | Flag | Destination |
|
|
24
|
+
| --- | --- | --- |
|
|
25
|
+
| Binary | `--bin` | `~/.local/bin/<key>` (or `--prefix`) |
|
|
26
|
+
| Bash completion | `--completions` | `~/.bash_completion.d/<key>` + `.bashrc` PATH snippet |
|
|
27
|
+
| Zsh completion | `--completions` | `~/.zsh/completions/_<key>` + `.zshrc` fpath snippet |
|
|
28
|
+
| Fish completion | `--completions` | `~/.config/fish/completions/<key>.fish` |
|
|
29
|
+
| Cursor skill | `--skill` | `~/.cursor/skills/<dir>/` when `~/.cursor` exists |
|
|
30
|
+
| Claude skill | `--skill` | `~/.claude/skills/<dir>/` when `~/.claude` exists |
|
|
31
|
+
| MCP config | `--mcp` | `~/.cursor/mcp.json` and `~/.claude.json` when MCP is enabled |
|
|
32
|
+
|
|
33
|
+
`--all` expands to `--bin`, `--completions`, `--skill`, and `--mcp` (when `mcpServer` is set).
|
|
34
|
+
|
|
35
|
+
Shells not on PATH are skipped silently (no warnings).
|
|
36
|
+
|
|
37
|
+
## Configuration
|
|
38
|
+
|
|
39
|
+
On the program root:
|
|
40
|
+
|
|
41
|
+
```typescript
|
|
42
|
+
install: {
|
|
43
|
+
enabled: false, // opt out of the install built-in
|
|
44
|
+
prefix: "~/.local/bin", // default bin directory
|
|
45
|
+
}
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
Environment:
|
|
49
|
+
|
|
50
|
+
- `INSTALL_PREFIX` — same as `install.prefix` / `--prefix`
|
|
51
|
+
|
|
52
|
+
## Flags
|
|
53
|
+
|
|
54
|
+
| Flag | Description |
|
|
55
|
+
| --- | --- |
|
|
56
|
+
| `--yes` | Skip confirmation (required for non-TTY unless `--json` / `--update`) |
|
|
57
|
+
| `--dry` | Preview changes; per-step messages on stderr with `[dry run]` |
|
|
58
|
+
| `--json` | Machine-readable output on stdout (implies `--yes`) |
|
|
59
|
+
| `--quiet` | Suppress summaries and per-step messages (requires `--yes`) |
|
|
60
|
+
| `--prefix <dir>` | Override binary install directory |
|
|
61
|
+
| `--update` | Update only artifacts already installed (implies `--bin` + `--yes`) |
|
|
62
|
+
| `--status` | Read-only inventory |
|
|
63
|
+
| `--uninstall` | Remove detected artifacts (scope with `--bin`, `--completions`, `--skill`, `--mcp`) |
|
|
64
|
+
|
|
65
|
+
## MCP merge behavior
|
|
66
|
+
|
|
67
|
+
When `--mcp` runs, entries are merged into `mcpServers[<name>]` with:
|
|
68
|
+
|
|
69
|
+
```json
|
|
70
|
+
{ "command": "<root.key>", "args": ["mcp"] }
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
If an existing entry differs, the command exits with an error unless `--yes` is passed (then it overwrites).
|
|
74
|
+
|
|
75
|
+
## Opt out
|
|
76
|
+
|
|
77
|
+
```typescript
|
|
78
|
+
const cli: CliCommand = {
|
|
79
|
+
key: "myapp",
|
|
80
|
+
description: "...",
|
|
81
|
+
install: { enabled: false },
|
|
82
|
+
// ...
|
|
83
|
+
};
|
|
84
|
+
```
|
package/docs/mcp.md
CHANGED
|
@@ -29,6 +29,8 @@ The process reads NDJSON requests from stdin and writes NDJSON responses to stdo
|
|
|
29
29
|
|
|
30
30
|
3. Point your MCP client at that command. See [Client setup](#client-setup).
|
|
31
31
|
|
|
32
|
+
Optionally install an agent skill for discovery without MCP: see [docs/ai-skills.md](ai-skills.md).
|
|
33
|
+
|
|
32
34
|
The `examples/nested.ts` demo enables MCP — try:
|
|
33
35
|
|
|
34
36
|
```bash
|
|
@@ -46,17 +48,17 @@ Add a server entry under `mcpServers` in your Cursor MCP config:
|
|
|
46
48
|
"mcpServers": {
|
|
47
49
|
"myapp": {
|
|
48
50
|
"command": "bun",
|
|
49
|
-
"args": ["run", "myapp.ts", "mcp"]
|
|
51
|
+
"args": ["run", "myapp.ts", "ai", "mcp"]
|
|
50
52
|
}
|
|
51
53
|
}
|
|
52
54
|
}
|
|
53
55
|
```
|
|
54
56
|
|
|
55
|
-
Use your real binary or script path. For a compiled CLI, `command` can be the installed binary and `args` can be `["mcp"]
|
|
57
|
+
Use your real binary or script path. For a compiled CLI, `command` can be the installed binary and `args` can be `["ai", "mcp"]`.
|
|
56
58
|
|
|
57
59
|
### Other MCP hosts
|
|
58
60
|
|
|
59
|
-
Any host that spawns a subprocess and wires stdin/stdout works the same way: the **command** is your app, and **`mcp`**
|
|
61
|
+
Any host that spawns a subprocess and wires stdin/stdout works the same way: the **command** is your app, and **`mcp`** starts the server.
|
|
60
62
|
|
|
61
63
|
## Configuration
|
|
62
64
|
|
|
@@ -83,7 +85,7 @@ mcpServer: {
|
|
|
83
85
|
|
|
84
86
|
## Tools
|
|
85
87
|
|
|
86
|
-
Every **user-defined leaf command** in your schema becomes one MCP tool. Built-ins (`completion`, `
|
|
88
|
+
Every **user-defined leaf command** in your schema becomes one MCP tool. Built-ins (`completion`, `ai`) are not exposed as tools.
|
|
87
89
|
|
|
88
90
|
### Tool names
|
|
89
91
|
|
|
@@ -284,7 +286,7 @@ You should get one JSON line on stdout with `result.capabilities` and `result.se
|
|
|
284
286
|
|
|
285
287
|
When MCP is enabled:
|
|
286
288
|
|
|
287
|
-
- Do not declare a top-level command named **`
|
|
289
|
+
- Do not declare a top-level command named **`ai`** — it is reserved for the built-in AI integration group.
|
|
288
290
|
- Do not declare a top-level command named **`completion`** — reserved for shell completions.
|
|
289
291
|
- Do not declare an option named **`schema`** — reserved for `--schema`.
|
|
290
292
|
|
package/index.d.ts
CHANGED
|
@@ -165,6 +165,15 @@ export interface CliMcpToolConfig {
|
|
|
165
165
|
*/
|
|
166
166
|
requiresEnv?: string[];
|
|
167
167
|
}
|
|
168
|
+
/**
|
|
169
|
+
* Root-only. Opt-out and defaults for the `install` built-in (compiled binaries only).
|
|
170
|
+
*/
|
|
171
|
+
export interface CliInstallConfig {
|
|
172
|
+
/** When `false`, hide/disable `install` (default: enabled). */
|
|
173
|
+
enabled?: boolean;
|
|
174
|
+
/** Default bin directory (default: `~/.local/bin`). Overridden by `INSTALL_PREFIX` env and `--prefix`. */
|
|
175
|
+
prefix?: string;
|
|
176
|
+
}
|
|
168
177
|
/**
|
|
169
178
|
* Base properties shared by all command nodes.
|
|
170
179
|
*/
|
|
@@ -179,6 +188,8 @@ export interface CliCommandBase {
|
|
|
179
188
|
options?: CliOption[];
|
|
180
189
|
/** Root-only. When set, enables the `mcp` built-in subcommand. */
|
|
181
190
|
mcpServer?: CliMcpServerConfig;
|
|
191
|
+
/** Root-only. Opt-out and defaults for `install` (compiled binaries only). */
|
|
192
|
+
install?: CliInstallConfig;
|
|
182
193
|
/** Leaf-only. Per-tool MCP exposure and metadata. */
|
|
183
194
|
mcpTool?: CliMcpToolConfig;
|
|
184
195
|
}
|
|
@@ -243,16 +254,7 @@ export interface CliInvokeResult {
|
|
|
243
254
|
* Never calls process.exit.
|
|
244
255
|
*/
|
|
245
256
|
export declare function cliInvoke(root: CliCommand, argv: string[]): Promise<CliInvokeResult>;
|
|
246
|
-
/**
|
|
247
|
-
* Validates the schema, parses argv, prints help or errors, runs completion or the leaf handler, then exits.
|
|
248
|
-
*
|
|
249
|
-
* @param root The root CliCommand.
|
|
250
|
-
* @param argv Override the default argv (process.argv.slice(2)).
|
|
251
|
-
*/
|
|
252
257
|
export declare function cliRun(root: CliCommand, argv?: string[]): Promise<never>;
|
|
253
|
-
/**
|
|
254
|
-
* Prints a red error line and contextual help on stderr, then exits with status 1.
|
|
255
|
-
*/
|
|
256
258
|
export declare function cliErrWithHelp(ctx: CliContext, msg: string): never;
|
|
257
259
|
/** True when stdin is a TTY. */
|
|
258
260
|
export declare const isInteractiveTty: boolean;
|
package/package.json
CHANGED
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { describe, expect, test, afterEach } from "bun:test";
|
|
2
|
+
import { cliBuiltinInstallCommand, installBuiltinOptions } from "./install.ts";
|
|
3
|
+
import { cliBuiltinMcpCommand } from "./mcp.ts";
|
|
4
|
+
import { cliPresentationRoot } from "./presentation.ts";
|
|
5
|
+
import { completionBashScript, completionFishScript, completionZshScript } from "./index.ts";
|
|
6
|
+
import { exportPresentationBuiltins } from "./export.ts";
|
|
7
|
+
import { CliCommand } from "../types.ts";
|
|
8
|
+
import { setCompiledExecutableOverride } from "../install/compiled.ts";
|
|
9
|
+
|
|
10
|
+
const fixture: CliCommand = {
|
|
11
|
+
key: "myapp",
|
|
12
|
+
description: "Demo app.",
|
|
13
|
+
mcpServer: { name: "myapp" },
|
|
14
|
+
commands: [
|
|
15
|
+
{
|
|
16
|
+
key: "hello",
|
|
17
|
+
description: "Say hello.",
|
|
18
|
+
handler: () => {},
|
|
19
|
+
},
|
|
20
|
+
],
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
afterEach(() => {
|
|
24
|
+
setCompiledExecutableOverride(null);
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
describe("builtins help copy", () => {
|
|
28
|
+
test("install command includes description and option text when compiled", () => {
|
|
29
|
+
setCompiledExecutableOverride(true);
|
|
30
|
+
const install = cliBuiltinInstallCommand(fixture);
|
|
31
|
+
expect(install.description).toContain("Install the binary");
|
|
32
|
+
expect(install.notes).toContain("bun build --compile");
|
|
33
|
+
const names = installBuiltinOptions(fixture).map((o) => o.name);
|
|
34
|
+
expect(names).toContain("all");
|
|
35
|
+
expect(names).toContain("mcp");
|
|
36
|
+
expect(names).toContain("prefix");
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
test("install omits --mcp option when mcpServer unset", () => {
|
|
40
|
+
setCompiledExecutableOverride(true);
|
|
41
|
+
const noMcp: CliCommand = { key: "x", description: "x", handler: () => {} };
|
|
42
|
+
const names = installBuiltinOptions(noMcp).map((o) => o.name);
|
|
43
|
+
expect(names).not.toContain("mcp");
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
test("mcp builtin description is user-facing", () => {
|
|
47
|
+
const mcp = cliBuiltinMcpCommand();
|
|
48
|
+
expect(mcp.description).toContain("MCP server");
|
|
49
|
+
expect(mcp.notes).toContain('["mcp"]');
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
describe("presentation root", () => {
|
|
54
|
+
test("includes mcp when mcpServer set", () => {
|
|
55
|
+
setCompiledExecutableOverride(false);
|
|
56
|
+
const root = cliPresentationRoot(fixture);
|
|
57
|
+
expect(root.commands?.map((c) => c.key)).toContain("mcp");
|
|
58
|
+
expect(root.commands?.map((c) => c.key)).not.toContain("install");
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
test("includes install when compiled", () => {
|
|
62
|
+
setCompiledExecutableOverride(true);
|
|
63
|
+
const root = cliPresentationRoot(fixture);
|
|
64
|
+
expect(root.commands?.map((c) => c.key)).toContain("install");
|
|
65
|
+
});
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
describe("completion emitters", () => {
|
|
69
|
+
test("fish script references app key and subcommands", () => {
|
|
70
|
+
setCompiledExecutableOverride(true);
|
|
71
|
+
const schema = cliPresentationRoot(fixture);
|
|
72
|
+
const fish = completionFishScript(schema);
|
|
73
|
+
expect(fish).toContain("complete -c myapp");
|
|
74
|
+
expect(fish).toContain("hello");
|
|
75
|
+
expect(fish).toContain("install");
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
test("bash script includes install flags when compiled", () => {
|
|
79
|
+
setCompiledExecutableOverride(true);
|
|
80
|
+
const schema = cliPresentationRoot(fixture);
|
|
81
|
+
const bash = completionBashScript(schema);
|
|
82
|
+
expect(bash).toContain("--all");
|
|
83
|
+
expect(bash).toContain("install");
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
test("zsh script registers compdef", () => {
|
|
87
|
+
const schema = cliPresentationRoot({ key: "zapp", description: "z", handler: () => {} });
|
|
88
|
+
const zsh = completionZshScript(schema);
|
|
89
|
+
expect(zsh).toContain("#compdef zapp");
|
|
90
|
+
expect(zsh).toContain("compdef _zapp zapp");
|
|
91
|
+
});
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
describe("schema export builtins", () => {
|
|
95
|
+
test("exportPresentationBuiltins includes install options when compiled", () => {
|
|
96
|
+
setCompiledExecutableOverride(true);
|
|
97
|
+
const builtins = exportPresentationBuiltins(fixture);
|
|
98
|
+
const install = builtins.find((b) => b.key === "install");
|
|
99
|
+
expect(install?.options?.find((o) => o.name === "all")?.description).toContain("binary");
|
|
100
|
+
});
|
|
101
|
+
});
|