feat: sanitize OpenAPI tag names for Commander.js - #28
Merged
Merged
Conversation
Tags with slashes, spaces, apostrophes or other special characters (e.g. Apify's 'Actors/Actor builds', \"Last Actor run's abort\") broke command registration because Commander.js interprets / as path separator and rejects spaces/quotes in command names. Now tag names are normalized via sanitizeCommandName() to lowercase-hyphenated form, and collisions get numeric suffixes (-2, -3, ...). Applied in both static and dynamic command builders. Split commander-builder.test.ts into per-concern files to stay within the 150-line gate. BREAKING: command group names are now always lowercase. Previously 'Pets' worked as a literal command; now it's 'pets'. This matches standard CLI convention and the existing simplifyName output. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Specs whose tags contain slashes, spaces, apostrophes or other special characters break command registration with errors like:
```
Error: cannot add command 'Actors/Actor' as already have command 'Actors/Actor'
```
Real-world examples: Apify ships tags like `Actors/Actor builds`, `Actors/Actor versions`, `Last Actor run's abort`, `Last Actor task run's default key-value store`.
Fix
Breaking change
Command groups are now always lowercase. `tocli petstore Pets list` becomes `tocli petstore pets list`. Matches the existing `simplifyName` behavior for operations and standard CLI convention.
Suggested release: 0.8.0 (minor bump because of the breaking change).
Test plan
🤖 Generated with Claude Code