Autogenerate CLI#1205
Draft
talagluck wants to merge 2 commits into
Draft
Conversation
|
Wrap the hand-written CLI source to the repo's printWidth, and exclude the auto-generated generated-commands.ts from Prettier (it's regenerated on every build, so formatting it would just be undone). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
a723a53 to
a95be30
Compare
commit: |
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.
This adds
gitbook2, a standalone CLI for exercising the GitBook API. It's a separate binary from the maingitbookCLI (which builds and publishes integrations) so I could develop the generated API commands in isolation without cluttering the stable command tree.The command tree is generated from
packages/api/spec/openapi.yamlbyscripts/generate-commands.ts— one command per public operation, named off the URL path (e.g.gitbook2 organizations list,gitbook2 spaces get <id>). It shares auth/config with the main CLI, and ships shell completion for bash/zsh/fish.Things that would be helpful for review:
fields — with a footer showing the count and the pagination cursor as a
ready-to-paste flag (
next page: --page <cursor>).--full.--fullrestores the complete dump, and--json/--yamlare untouched, soscripts and agents still get the full structured response. When piped (not a
TTY) it defaults to YAML.
I pulled the formatting logic into
packages/cli/src/output.ts(instead of inlining it in the generated file) so it has a single source of truth and can be unit-tested directly — seeoutput.test.ts(bun test).A few notes:
generated-commands.tsis auto-generated — don't hand-edit it;prebuildregenerates it from the spec vianpm run generate-commands.gitbook2/cli2are working names for now — I'll rename before this goes in for real.How to test
gitbook2Requires Node ≥18 and bun.
Then run any command via
node dist/cli2.js <command>:Optional: install and run it as
gitbook2instead ofnode dist/cli2.jsRun the formatting unit tests