Skip to content

feat(cli): generate the CLI reference with a dev script - #2091

Draft
mishushakov wants to merge 2 commits into
mishushakov/commander-cli-upgradefrom
mishushakov/cli-reference-generator
Draft

mishushakov wants to merge 2 commits into
mishushakov/commander-cli-upgradefrom
mishushakov/cli-reference-generator

Conversation

@mishushakov

@mishushakov mishushakov commented Nov 5, 2026 •

Copy link
Copy Markdown
Member

Summary

Replaces the hidden -cmd2md flag in the published binary with a dev-only script, pnpm run generate:reference. The script walks the command tree through commander's public Help API (visibleCommands, visibleOptions, visibleArguments, optionDescription, …) and writes sdk_ref/<command>.md for e2b-dev/docs to publish.

Stacked on #2090. The matching docs-repo change is e2b-dev/docs#626.

Why

The old commands2md read commander's internal fields directly, which caused these problems on the docs site:

Problem Now
Hidden, deprecated options documented (--team, the ignored --config) Same options as --help
Positional arguments and aliases never documented Arguments section and Alias line
[default: [object Object]] on every -e, --env (stripped by a regex in the docs repo) Defaults formatted by commander; --env no longer has a fake default
"HTML escaping" replaced < with < (no-op); colour stripping only worked because stdout wasn't a TTY <placeholder> tokens become inline code; other <>{} become entities; ANSI stripped with util.stripVTControlCharacters. All pages compile with @mdx-js/mdx 3
json2md and the flag shipped in dist/index.js Removed from the bundle and from devDependencies

Changes

  • scripts/reference.ts (renderer) and scripts/generate-reference.ts (writes sdk_ref/), run with tsx (new devDependency). lint and format now cover scripts/.
  • tests/reference.test.ts: unit tests for the renderer, plus file snapshots of the real reference in tests/__snapshots__/reference/*.md. Help-text changes now show up in review as docs diffs; update them with pnpm vitest run -u tests/reference.test.ts.
  • -e, --env (sandbox create, connect, exec): parseEnv starts its own accumulator instead of taking a {} option default. This drops (default: {}) from --help and stops one object being shared across parses (patch changeset).
  • auth login reads package.json directly instead of importing the CLI entrypoint (src/index.ts). Importing the entrypoint ran main() whenever the command tree was loaded on its own, which is how the script and tests load it.

Usage

$ pnpm --filter @e2b/cli run generate:reference
Generated sdk_ref/auth.md
Generated sdk_ref/template.md
Generated sdk_ref/sandbox.md
## e2b sandbox connect

connect terminal to already running sandbox

### Usage

```bash
e2b sandbox connect [options] <sandboxID>
```

**Alias:** `cn`

### Arguments

- `<sandboxID>`: connect to sandbox with `<sandboxID>`

### Options

- `-u, --user <user>`: user to start the terminal session as
- `-c, --cwd <dir>`: working directory for the terminal session
- `-e, --env <KEY=VALUE>`: set environment variable for the terminal session (repeatable)
$ e2b sandbox connect --help
...
  -e, --env <KEY=VALUE>  set environment variable for the terminal session
                         (repeatable)

Merge order

Merge e2b-dev/docs#626 before the first @e2b/cli release that contains this PR. It runs the new script when a tag has it and keeps -cmd2md for older tags. Without it, the reference sync fails for that release.

Testing

  • pnpm run test in packages/cli: 24 files / 158 tests pass, including the template create backend test against prod.
  • generate:reference output is byte-identical to the vitest snapshots.
  • Ran the docs repo's generateCli() against this branch end to end; the resulting .mdx pages compile with @mdx-js/mdx 3.
  • Repo-wide pnpm run lint and pnpm run typecheck pass; knip reports nothing new.

Closes SDK-432.

🤖 Generated with Claude Code

@mishushakov
mishushakov added this pull request to stack #2092 November 5, 2026 15:08
@cla-bot cla-bot Bot added the cla-signed label Nov 5, 2026
@cursor

cursor Bot commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

PR Summary

Low Risk
Changes are mostly docs generation and help text; the --env parser behavior is preserved with a small accumulator fix and covered by tests.

Overview
Replaces the hidden -cmd2md path and json2md-based commands2md with a dev-only pnpm run generate:reference flow that renders sdk_ref/*.md through Commander’s public Help API, so published docs match --help (visible options/commands, arguments, aliases, sane defaults).

The new scripts/reference.ts renderer adds MDX-safe escaping and strips ANSI; tests/reference.test.ts plus file snapshots lock the output that e2b-dev/docs consumes. json2md is dropped from the bundle and devDependencies; tsx runs the generator.

For sandbox create, connect, and exec, repeatable -e, --env no longer uses a {} option default—parseEnv seeds its own accumulator—removing misleading (default: {}) from help and avoiding a shared default object across parses.

auth login reads package.json directly so loading the command tree for docs/tests does not pull in src/index.ts and run the CLI main() hook.

Reviewed by Cursor Bugbot for commit c1ba4e8. Bugbot is set up for automated code reviews on this repo. Configure here.

@changeset-bot

changeset-bot Bot commented Nov 5, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: c1ba4e8

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@e2b/cli Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TASTE.md review: no violations. This PR only changes CLI internals and docs tooling (the reference generator, the --env default, and the pkg import), so most TASTE rules, which cover the SDK surface, don't apply. The ones that do (T-20 absence is undefined, T-56 version read from package.json, T-69/T-70 docs, T-62/T-63 error messages) all pass.

Written by Devin

@mishushakov mishushakov changed the title mishushakov/cli reference generator feat(cli): generate the CLI reference with a dev script Nov 5, 2026
@github-actions

github-actions Bot commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

Package Artifacts

Built from b5c17ca. Download artifacts from this workflow run.

JS SDK (e2b@2.63.1-mishushakov-cli-reference-generator.0, with @e2b/dockerfile-utils@0.1.2-mishushakov-cli-reference-generator.0):

npm install ./e2b-dockerfile-utils-0.1.2-mishushakov-cli-reference-generator.0.tgz ./e2b-2.63.1-mishushakov-cli-reference-generator.0.tgz

CLI (@e2b/cli@2.23.1-mishushakov-cli-reference-generator.0):

npm install ./e2b-cli-2.23.1-mishushakov-cli-reference-generator.0.tgz

Code Interpreter JS SDK (@e2b/code-interpreter@2.9.2-mishushakov-cli-reference-generator.0):

npm install ./e2b-code-interpreter-2.9.2-mishushakov-cli-reference-generator.0.tgz

Desktop JS SDK (@e2b/desktop@2.5.1-mishushakov-cli-reference-generator.0):

npm install ./e2b-desktop-2.5.1-mishushakov-cli-reference-generator.0.tgz

Python SDK (e2b==2.63.0+mishushakov.cli.reference.generator, with e2b-dockerfile-utils==0.1.1+mishushakov.cli.reference.generator):

pip install ./e2b_dockerfile_utils-0.1.1+mishushakov.cli.reference.generator-py3-none-any.whl ./e2b-2.63.0+mishushakov.cli.reference.generator-py3-none-any.whl

Code Interpreter Python SDK (e2b-code-interpreter==2.11.9+mishushakov.cli.reference.generator):

pip install ./e2b_code_interpreter-2.11.9+mishushakov.cli.reference.generator-py3-none-any.whl

Desktop Python SDK (e2b-desktop==2.7.2+mishushakov.cli.reference.generator):

pip install ./e2b_desktop-2.7.2+mishushakov.cli.reference.generator-py3-none-any.whl

mishushakov and others added 2 commits November 5, 2026 16:17
The repeatable `-e, --env` option seeded its accumulator through the
option default, so help printed `(default: {})`, and the same object was
shared across parses. parseEnv now starts a fresh object itself.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Replace the `-cmd2md` flag baked into the shipped binary with
`pnpm run generate:reference`, a tsx script that walks the command tree
through commander's public Help API and writes sdk_ref/<command>.md.

Compared to commands2md:
- hidden options (deprecated --team, --config) are no longer documented
- positional arguments and aliases are documented
- defaults are formatted by commander, no more `[object Object]`
- free text is escaped for MDX instead of the no-op `<` replacement
- json2md and the flag no longer ship in dist/index.js

The rendered reference is snapshotted in tests/__snapshots__/reference so
help text changes show up in review. login.ts now reads package.json
directly instead of importing the entrypoint, which ran main() when the
command tree was imported on its own.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@mishushakov
mishushakov force-pushed the mishushakov/cli-reference-generator branch from f12fc8c to c1ba4e8 Compare November 5, 2026 15:18
@linear-code

linear-code Bot commented Nov 5, 2026

Copy link
Copy Markdown

SDK-432

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant