Skip to content

Commit 28757dd

Browse files
committed
Fixed ansi/color formatting issue with respect to generated documentation
1 parent 119f4ae commit 28757dd

7 files changed

Lines changed: 27 additions & 21 deletions

File tree

.claude/skills/ably-new-command/SKILL.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,7 @@ If the new command shouldn't be available in the web CLI, add it to the appropri
434434
After creating command and test files, always run:
435435
```bash
436436
pnpm prepare # Build + update manifest
437-
pnpm exec oclif readme # Regenerate README.md from command metadata
437+
pnpm generate-doc # Regenerate command documentation
438438
pnpm exec eslint . # Lint (must be 0 errors)
439439
pnpm test:unit # Run tests
440440
```

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ node_modules/
3131
# oclif files
3232
oclif.manifest.json
3333
oclif.lock
34-
GENERATED_README.md
34+
GENERATED_DOC.md
3535

3636
# OS generated files
3737
**/.DS_Store

AGENTS.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
```bash
88
pnpm prepare # 1. Build + update manifest
9-
pnpm generate-readme # 2. Regenerate command docs (gitignored)
9+
pnpm generate-doc # 2. Regenerate docs (gitignored)
1010
pnpm exec eslint . # 3. Lint (MUST be 0 errors)
1111
pnpm test:unit # 4. Test (at minimum)
1212
pnpm test:tty # 5. TTY tests (local only, skip in CI)

CONTRIBUTING.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ All code changes, whether features or bug fixes, **MUST** follow the mandatory w
88

99
In summary, this involves:
1010

11-
1. **Build:** Run `pnpm prepare` to compile and update manifests, then `pnpm exec oclif readme` to regenerate the README.
11+
1. **Build:** Run `pnpm prepare` to compile and update manifests, then `pnpm generate-doc` to regenerate the command documentation.
1212
2. **Lint:** Run `pnpm exec eslint .` and fix all errors/warnings.
1313
3. **Test:** Run relevant tests (`pnpm test:unit`, `pnpm test:integration`, `pnpm test:e2e`, `pnpm test:playwright`, or specific files) and ensure they pass. For interactive mode changes, also run `pnpm run test:tty` (requires a real terminal, not run in CI). Add new tests or update existing ones as needed.
1414
4. **Document:** Update all relevant documentation (`docs/`, `AGENTS.md`, `README.md`) to reflect your changes.
@@ -53,10 +53,10 @@ This allows testing CLI changes against local server modifications before deploy
5353
1. Make sure all checks are passing on main
5454
2. Create a new release branch, in the format `release/<version>` where the version is the SemVer version of the release. In that branch:
5555
- Update the `package.json` version to the new version.
56-
- Run `pnpm exec oclif readme` to regenerate the README with updated command documentation.
56+
- Run `pnpm generate-doc` to regenerate the command documentation.
5757
- Update the `CHANGELOG.md` with any user-affecting changes since the last release.
58-
- Review the generated README.md changes to ensure they're correct.
59-
- Stage all changes: `git add package.json README.md CHANGELOG.md`
58+
- Review the generated `GENERATED_DOC.md` output locally to ensure updated commands documentation is correct.
59+
- Stage all changes: `git add package.json CHANGELOG.md`
6060
- Commit all changes with a message like `chore: prepare release <version>`.
6161
- Update the `package.json` for `packages/react-web-cli`.
6262
3. Once the release branch is approved, merge it into main.

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# Ably CLI
22

33
[![npm version](https://badge.fury.io/js/@ably%2Fcli.svg)](https://badge.fury.io/js/@ably%2Fcli)
4-
[![Node](https://img.shields.io/node/v/@ably/cli)](https://nodejs.org)
5-
[![License](https://img.shields.io/npm/l/@ably/cli)](https://github.com/ably/ably-cli/blob/main/LICENSE)
4+
[![Node](https://img.shields.io/node/v/%40ably%2Fcli)](https://nodejs.org)
5+
[![License](https://img.shields.io/npm/l/%40ably%2Fcli)](https://github.com/ably/ably-cli/blob/main/LICENSE)
66

77
The Ably CLI brings the full power of Ably to your terminal. You can use it to manage your Ably account and its resources, and to explore Ably's APIs and features.
88

@@ -15,7 +15,7 @@ The Ably CLI interacts with:
1515

1616
## Installation
1717

18-
The Ably CLI is available as an NPM package, install using
18+
The Ably CLI is available as an NPM package. Install it using:
1919

2020
```shell
2121
npm install -g @ably/cli
@@ -29,9 +29,9 @@ For a list of all available commands, run:
2929
ably help
3030
```
3131

32-
Visit [Official Ably Documentation](https://ably.com/docs/platform/tools/cli) for CLI login, features and usage.
32+
Visit [the official Ably documentation](https://ably.com/docs/platform/tools/cli) for CLI login, features, and usage.
3333

34-
# Contributing
34+
## Contributing
3535

3636
Please see [`CONTRIBUTING.md`](CONTRIBUTING.md) for the development workflow, testing requirements, and release process.
3737

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
"prepare": "[ -d .git ] && [ -d .githooks ] && git config core.hooksPath .githooks || true; pnpm run build && CI=true ABLY_INTERACTIVE=false oclif manifest",
5252
"postinstall": "[ \"$CI\" = \"true\" ] || (test -f ./dist/scripts/postinstall-welcome.js && node ./dist/scripts/postinstall-welcome.js || echo \"Skipping welcome script (not found)\")",
5353
"preversion": "pnpm run prepare",
54-
"generate-readme": "[ -f GENERATED_README.md ] || printf '<!-- toc -->\\n<!-- tocstop -->\\n<!-- usage -->\\n<!-- usagestop -->\\n<!-- commands -->\\n<!-- commandsstop -->\\n' > GENERATED_README.md && oclif readme --readme-path GENERATED_README.md",
54+
"generate-doc": "rm -f GENERATED_DOC.md && printf '<!-- toc -->\\n<!-- tocstop -->\\n<!-- usage -->\\n<!-- usagestop -->\\n<!-- commands -->\\n<!-- commandsstop -->\\n' > GENERATED_DOC.md && (GENERATING_DOC=true NO_COLOR=1 oclif readme --readme-path GENERATED_DOC.md)",
5555
"validate": "./scripts/pre-push-validation.sh",
5656
"pre-commit": "pnpm validate",
5757
"ai-init": "echo 'AI Assistant Instructions:' && cat .claude/CLAUDE.md",

src/help.ts

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,8 @@ export default class CustomHelp extends Help {
3333
this.configManager = createConfigManager();
3434
}
3535

36-
// Override formatHelpOutput to apply stripAnsi when necessary
36+
// Override formatHelpOutput to apply interactive-mode transformations
3737
formatHelpOutput(output: string): string {
38-
// Check if we're generating readme (passed as an option from oclif)
39-
if (this.opts.stripAnsi || process.env.GENERATING_README === "true") {
40-
output = stripAnsi(output);
41-
}
42-
4338
// Strip "ably" prefix when in interactive mode
4439
if (this.interactiveMode) {
4540
output = this.stripAblyPrefix(output);
@@ -48,6 +43,11 @@ export default class CustomHelp extends Help {
4843
return output;
4944
}
5045

46+
// Check if ANSI codes should be stripped (oclif readme generation or while generating docs via GENERATING_DOC)
47+
private shouldStripAnsi(): boolean {
48+
return !!(this.opts.stripAnsi || process.env.GENERATING_DOC === "true");
49+
}
50+
5151
// Helper to strip "ably" prefix from command examples in interactive mode
5252
private stripAblyPrefix(text: string): string {
5353
if (!this.interactiveMode) return text;
@@ -193,7 +193,10 @@ export default class CustomHelp extends Help {
193193
} else {
194194
output = this.formatStandardRoot();
195195
}
196-
return output; // Let the overridden render handle stripping
196+
if (this.shouldStripAnsi()) {
197+
output = stripAnsi(output);
198+
}
199+
return output;
197200
}
198201

199202
formatStandardRoot(): string {
@@ -486,7 +489,10 @@ export default class CustomHelp extends Help {
486489
}
487490
}
488491
}
489-
return output; // Let the overridden render handle stripping
492+
if (this.shouldStripAnsi()) {
493+
output = stripAnsi(output);
494+
}
495+
return output;
490496
}
491497

492498
// Re-add the check for web CLI mode command availability

0 commit comments

Comments
 (0)