Repository navigation
fix(cli): validate --lang, fix --detail level inversion, expose global flags in subcommand help - #2407
fix(cli): validate --lang, fix --detail level inversion, expose global flags in subcommand help#2407josephfarina wants to merge 4 commits into
Conversation
…l flags in subcommand help
- Validate --lang against the supported set (en, zh, dense). Unsupported
values now exit 1 with a clear message instead of silently falling
back to English. JSON callers get a typed error envelope.
- Warn on stderr when --lang zh is requested: the translation coverage
is incomplete and prose still falls back to English. (Follow-up:
flesh out zh translations across all .doc.mjs files.)
- Reject combining --lang with the legacy --zh / --dense shortcuts
instead of silently picking one.
- Fix --detail level inversion on list views. Previously
'component --list --detail brief' produced ~26x MORE output than
'--detail full'; now brief < compact < full as documented:
brief -> just names (component.list)
compact -> names + short description (component.compact-list)
full -> names + description + import path (component.detailed-list)
When the user does not pass --detail, list views default to brief
(just names) so 'xds component --list' stays terse.
- Make formatHookFull a true superset of formatHookCompact (adds Import,
Examples, Related sections) so single-hook detail levels are also
brief < compact < full.
- Surface global flags (--json, --lang, --detail, --zh, --dense) and
add an Examples: section in the --help output of component, hook,
docs, init, swizzle, discover, and upgrade subcommands.
- 'xds --version --json' now emits a typed JSON envelope:
{ type: 'version', data: { version: ... } }.
Tests: +26 (lib/lang.test.mjs, commands/cli-flags.test.mjs).
All 616 cli vitest tests pass; pnpm lint clean.
|
Someone is attempting to deploy this pull request to the Meta Open Source Team on Vercel. No GitHub account was found matching the commit author email address. To deploy this pull request, the commit author's email address needs to be associated with a GitHub account. Learn more about how to change the commit author information. |
🚀 Vercel Preview Deployment
|
PR Analysis Report📚 Storybook PreviewView Storybook for this PR 🧪 Sandbox PreviewView Sandbox for this PR No new or modified components detected. Bundle Size Summary
Accessibility AuditStatus: No accessibility violations detected. Generated by PR Enrichment workflow | Storybook | Sandbox | View full report |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
template, template get, theme, and theme build subcommands did not re-surface the inherited global flags (--json/--lang/--detail) or an Examples block in their --help, unlike component/hook/docs/discover/ upgrade. Wire addCommonHelp into all four and add subprocess tests proving each --help shows the global flags and Examples.
gap-report and its setup subcommand did not re-surface the inherited global flags (--json/--lang/--detail) or an Examples block in --help. Wire addCommonHelp into both and add subprocess tests.
The global --lang flag is advertised on every subcommand's help (declared
on the root program), but only component/hook/discover/docs translate.
Write/action commands (init, template, theme, upgrade, swizzle, build,
gap-report) silently ignored it and produced English.
Add a global preAction hook that validates --lang / --zh / --dense before
any side effects:
- unsupported locale -> exit 1 (or structured { error } under --json)
- partially-translated locale (zh) -> exit 0 + one-time stderr warning
- --lang combined with legacy --zh/--dense -> exit 1 (ambiguous)
init --all --lang xx now exits 1 with zero files written (no half-writes).
Adds 9 subprocess/e2e tests proving the behavior across read and write
commands, the --json contract, side-effect-free rejection, and i18n honesty.
Closes checklist items #1 (flag validation) and #10 (i18n honesty) for the
write/action commands not covered by #2407.
Fixes four CLI usability issues surfaced by recent agent-facing audits:
1. `--lang` was silently lying
`--lang fr`, `--lang ja`, `--lang zh` all returned English. The flag is advertised in `--help` but had no validator, so unsupported locales were silently swallowed and `zh` was only partially translated (props translated, prose not).
Fix:
```
Warning: --lang zh translations are incomplete. Some prose will fall back to English.
```
2. `--detail` levels were inverted on list views
Before:
So `brief` was 26× larger than `full` — exactly backwards.
After:
Same fix applied to `xds hook --list`. Detail levels now follow the documented `brief < compact < full` ordering, and all three produce different output.
JSON envelope types reflect the new contract:
Implicit defaults preserved: when no `--detail` flag is passed on a list view, we default to `brief` so `xds component --list` stays terse for humans. Single-component views still default to `full`.
Bonus fix: `formatHookFull` was missing the `## Import` / `## Related` / `## Examples` sections that `formatHookCompact` already had, so `compact` could be longer than `full` for single hooks. `formatHookFull` is now a strict superset.
3. Subcommand `--help` omitted all global flags & had no examples
Before:
```
$ xds component --help
Usage: xds component [options] [name]
…
Options:
--list …
--category …
-h, --help display help for command
```
No mention of `--json`, `--lang`, or `--detail` — even though those flags significantly change the output. No `Examples:` section anywhere in the CLI.
Fix: new `addCommonHelp(cmd, examples)` helper in `packages/cli/src/utils/help.mjs` injects an `Examples:` block plus a "Global Options (inherited from `xds`)" reference into every subcommand. Wired into: `component`, `hook`, `docs`, `init`, `swizzle`, `discover`, `upgrade`.
4. `xds --version --json` returned plain text
```
$ xds --version --json
0.0.14
```
Fix:
```
$ xds --version --json
{
"type": "version",
"data": {
"version": "0.0.14"
}
}
```
Plain `xds --version` still returns plain text.
Tests
Files