Repository navigation
Add eager --completions flag and .help() config builder - #43
Conversation
…igurable help
Reworks how a default command and built-in completions surface in root help,
and makes root-help rendering configurable by consumers.
- `.default(cmd)` now registers the command only as the root surface, not a
named subcommand: it is no longer invokable by its own name and is omitted
from the `Commands:` list by default. Root help renders its args/flags inline
even alongside sibling commands; a sole default shows its own usage line.
- `.completions({ as: 'flag' })` exposes an eager `--completions <shell>` flag
instead of a subcommand, intercepted in the planner. `--completions` with no
value auto-detects the shell from `$SHELL`, falling back to `$PSModulePath`
for PowerShell (which never sets `$SHELL`). Adds `detectShell`/`normalizeShell`.
- `.help(config)` builder + `inlineDefault`/`showDefaultInCommands`/`footer`
HelpOptions, merged under runtime `options.help`.
BREAKING CHANGE: a default command is no longer a named route and is hidden from
the root commands list by default; re-enable the list entry with
`.help({ showDefaultInCommands: true })`.
|
Important Review skippedAuto reviews are limited based on label configuration. 🏷️ Required labels (at least one) (1)
🚫 Excluded labels (none allowed) (2)
Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Repository YAML (base), Organization UI (inherited) Review profile: ASSERTIVE Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
📝 WalkthroughWalkthroughThis PR adds an eager root Sequence Diagram(s)sequenceDiagram
participant CLIBuilder
participant planInvocation
participant execute
participant detectShell
CLIBuilder->>planInvocation: argv + schema
planInvocation->>planInvocation: intercept --completions
planInvocation-->>execute: root-completions outcome
execute->>detectShell: detect shell from env if needed
detectShell-->>execute: resolved shell
execute->>execute: emit script or JSON
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes Possibly related PRs
Suggested labels
🚥 Pre-merge checks | ✅ 10 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (10 passed)
Comment |
commit: |
- root help: honor HelpOptions.binName in the usage line, merged default-command usage, and footer instead of hardcoding schema.name - root help: advertise the eager --completions flag even when inlineDefault is false (it is a root option, not part of the default-command inline surface) - docs: scope the .completions() snapshot note to subcommand mode; flag mode generates from the final schema at execute time - tests: add binName and inlineDefault-with-completions coverage; add the repo's // === / // --- section markers to the new test file
Deploying with
|
| Status | Name | Latest Commit | Updated (UTC) |
|---|---|---|---|
| 🚫 Deployment cancelled View logs |
dreamcli | 703a0ae | Jun 30 2026, 11:05 AM |
- release: bump package.json and deno.json to 3.0.0 and move the CHANGELOG
[Unreleased] entries under [3.0.0] (breaking: default command is no longer a
named route)
- cli: reject a command/default flag named `completions` while
.completions({ as: 'flag' }) is active — the planner intercepts `--completions`
before dispatch, so such a flag would be unreachable. Enforced in
.completions({ as: 'flag' }), .command(), and .default(), including nested
subcommands and long aliases
…ard orders
- the "Could not detect shell" suggestion now references the resolved
helpOptions.binName instead of schema.name, matching the rest of the
root-help/completions path
- test: also assert the .completions({ as: 'flag' }) → .command() ordering
rejects a command reserving the --completions name
This comment was marked as resolved.
This comment was marked as resolved.
--completions flag and .help() config builder
…next` - bump package.json and deno.json to 3.0.0-rc.1; rename the CHANGELOG section and compare links to [3.0.0-rc.1] - publish-npm.yml: derive the npm dist-tag from the version — prerelease versions (containing a `-`) publish under `next`, stable versions under `latest` — so the RC never lands on the default `latest` tag
Signed-off-by: Kaj Kowalski <info@kajkowalski.nl>
Merging master (#49 numeric constraints) made `numberConstraints` a required field on `FlagSchema`. The synthetic render-only enum flag built for the eager `--completions` flag omitted it, breaking typecheck. Set it to `undefined`, matching every non-number flag.
Promote the accumulated 3.0.0 notes from [Unreleased] to a dated [3.0.0-rc.1] section. Version files were already bumped to 3.0.0-rc.1 in #43; compare links already point at v3.0.0-rc.1.
Summary
This PR introduces two major features to enhance CLI customization:
Eager
--completions <shell>flag — An alternative to thecompletionssubcommand that exposes shell completion as a root-level flag, ideal for single-command CLIs. The planner intercepts the flag before dispatch, auto-detects the shell from the environment if needed, and prints the completion script..help()builder method — Allows configuration of root-help rendering behavior throughinlineDefault,showDefaultInCommands, andfooteroptions, merged under runtimeoptions.help.Shell normalization and detection helpers — Exported
normalizeShell()anddetectShell()functions that parse shell tokens (bare names,$SHELLpaths, Windows executables) and auto-detect from environment variables.Key Changes
.completions({ as: 'flag' })— New option to register completion as an eager flag instead of a subcommand. When active, the planner intercepts--completions [shell]before dispatch and generates the script. Root help advertises the flag in itsFlags:section.Shell auto-detection —
--completionswithout a value resolves the target shell from the environment:$SHELL(parsed as an interpreter path) wins when it names a supported shell; otherwise$PSModulePathpresence selects PowerShell (the reliable signal forpwsh)..help(config)builder — New method to configure root-help defaults. AcceptsinlineDefault(render default command's args/flags inline),showDefaultInCommands(list default in Commands table),footer(show help hint), plus existingwidth/hyperlinks. Builder config merges under runtimeoptions.help(runtime wins).Default command as root surface — BREAKING:
.default(cmd)now registers the command only as the default, not as a named subcommand. It is the CLI's root surface (its args/flags render inline in help) and is omitted from theCommands:list by default. This change allows a single-command CLI with.completions({ as: 'flag' })to keep the root clean.Root help refactoring —
formatRootHelp()now handles inline default rendering, completions flag advertisement, and configurable footer/command listing. Helper functionsresolveSurfaceCommand()andcompletionsFlagSchema()build the synthetic flag schema for help display.Planner enhancements — New
planCompletionsFlag()function detects and validates the eager flag before dispatch, with proper error handling for unknown shells and support for--completions=<shell>syntax.Root surface normalization —
RootSurfaceinterface now distinguishesvisibleSubcommands(real commands, excluding default) fromvisibleCommands(all declared commands), with boolean flagshasVisibleSubcommandsandhasVisibleDefault.Implementation Details
CLISchema.completionsFlagand passed to the planner for interception.CLISchema.helpConfigand merged with runtime options informatRootHelp().pwsh↔powershellaliasing and strips Windows executable extensions.resolveSurfaceCommand()so it only appears in help when configured.cli-completions-flag.test.tscovering registration, interception, auto-detection, and help rendering.