feat: display option aliases in help output and hide auto-generated ones#90
feat: display option aliases in help output and hide auto-generated ones#90AgentEnder merged 3 commits intomainfrom
Conversation
Closes #89 Aliases registered via `option({ alias: [...] })` are now displayed alongside the primary flag in help text (e.g. `--help, -h`). Auto-generated aliases (strip-dashed camelCase/dashed forms and localized keys) are tracked internally and excluded from help to avoid noise.
|
View your CI Pipeline Execution ↗ for commit 1b0a35b
☁️ Nx Cloud last updated this comment at |
Aliases can now be declared either as plain strings or as
`{ name, hidden }` objects. Aliases with `hidden: true` remain
functional at parse time but are omitted from `--help` output and from
generated documentation. `hidden` defaults to `false` so aliases are
visible by default.
The internal `autoAliases` field was renamed to `hiddenAliases` to
cover both user-hidden aliases and the parser-generated ones
(strip-dashed conversions, localized keys).
There was a problem hiding this comment.
Nx Cloud is proposing a fix for your failed CI:
We fixed a TypeScript compilation failure caused by using Omit<UnknownOptionConfig, 'alias'> in the InternalOptionConfig definition, which silently dropped variant-specific fields like properties from the discriminated union. Restoring the intersection form (UnknownOptionConfig & { ... }) makes InternalOptionConfig a proper subtype of UnknownOptionConfig, and the alias field is normalized inline in parsers/object.ts to satisfy the narrowed string[] expectation.
Tip
✅ We verified this fix by re-running parser:extract-docs:api.
Suggested Fix changes
diff --git a/packages/parser/src/lib/option-types/index.ts b/packages/parser/src/lib/option-types/index.ts
index 2d2bd81..73ac4a3 100644
--- a/packages/parser/src/lib/option-types/index.ts
+++ b/packages/parser/src/lib/option-types/index.ts
@@ -14,7 +14,7 @@ export * from './string';
export type { OptionConfig, UnknownOptionConfig };
export type Internal<T extends UnknownOptionConfig> = T & InternalOptionConfig;
-export type InternalOptionConfig = Omit<UnknownOptionConfig, 'alias'> & {
+export type InternalOptionConfig = UnknownOptionConfig & {
key: string;
position?: number;
/**
diff --git a/packages/parser/src/lib/parsers/object.ts b/packages/parser/src/lib/parsers/object.ts
index aac905e..005dfbb 100644
--- a/packages/parser/src/lib/parsers/object.ts
+++ b/packages/parser/src/lib/parsers/object.ts
@@ -7,8 +7,7 @@ import { tryParseValue } from '../parser';
import { parserMap } from './parser-map';
import { Parser } from './typings';
-export const objectParser: Parser<Internal<ObjectOptionConfig<any, any>>> =
- ({
+export const objectParser: Parser<Internal<ObjectOptionConfig<any, any>>> = ({
tokens,
config,
providedFlag,
@@ -58,6 +57,9 @@ export const objectParser: Parser<Internal<ObjectOptionConfig<any, any>>> =
config: {
...propConfig,
key: `${config.key}.${parts.join('.')}`,
+ alias: propConfig.alias?.flatMap((a) =>
+ typeof a === 'string' ? [a] : [a.name]
+ ),
},
tokens,
current: currentValue,
@@ -78,7 +80,7 @@ export const objectParser: Parser<Internal<ObjectOptionConfig<any, any>>> =
let currentValue: any;
let currentConfig: UnknownOptionConfig = config;
let last: string;
-
+
while (true) {
if (!currentKey) {
return {
Or Apply changes locally with:
npx nx-cloud apply-locally jIrC-Xdjy
Apply fix locally with your editor ↗ View interactive diff ↗
🎓 Learn more about Self-Healing CI on nx.dev
Using `Omit<UnknownOptionConfig, 'alias'>` flattened the option-config union and broke type inference at the usage sites that rely on the discriminants. Revert to an intersection-based definition. The alias array is still normalized to plain strings at runtime in `option()`; downstream `.includes(string)` calls still type-check because `string` extends `string | AliasConfig`. Also regenerate docs-site output now that hidden aliases (strip-dashed auto aliases) are filtered from generated documentation.
|
Docs Preview: https://craigory.dev/cli-forge/pr/90/ |
Summary
This PR enhances the help output formatting to display user-defined option aliases alongside their primary names, while filtering out automatically generated aliases (from strip-dashed conversions and localization).
Key Changes
format-help.tsto display option aliases in the format--option, -a, --aliasin help textautoAliasesfield toInternalOptionConfigto distinguish between user-provided and automatically generated aliasesparser.tsto track which aliases were auto-generated via strip-dashed conversions or localizationImplementation Details
buildFlagColumn()helper formats flag names with proper dash prefixes (-for single char,--for multi-char)getDisplayAliases()filters aliases to exclude both the primary display key and any auto-generated aliaseshttps://claude.ai/code/session_01Xn7GsCWNdxtR8wYYqE1Cdr