Skip to content

feat(cli): shell completion support for CLI v2 and fix v1 side effects#15113

Draft
iamnamananand996 wants to merge 1 commit intomainfrom
devin/1776429862-cli-v2-shell-completion
Draft

feat(cli): shell completion support for CLI v2 and fix v1 side effects#15113
iamnamananand996 wants to merge 1 commit intomainfrom
devin/1776429862-cli-v2-shell-completion

Conversation

@iamnamananand996
Copy link
Copy Markdown
Contributor

Description

Linear ticket: Closes FER-8704

Shell completion currently triggers upgrade notices and slow network calls every time the user presses TAB. This PR fixes those side effects in CLI v1 and adds full shell completion support to CLI v2, including content-aware completions for workspace-derived flags.

Changes Made

CLI v1 — Fix side effects during completion (packages/cli/cli/src/cli.ts)

  • Detect --get-yargs-completions in process.argv early in runCli()
  • Call cliContext.suppressUpgradeMessage() to prevent upgrade notices from appearing during TAB completion
  • Skip getIntendedVersionOfCli() (network call for version redirection) during completion mode so TAB stays fast

CLI v2 — Add shell completion (packages/cli/cli-v2/src/cli.ts)

  • Register .completion() on the yargs instance to enable fern completion (outputs the shell completion script) and --get-yargs-completions (provides completions on TAB)
  • Skip getOrCreateFernRunId() telemetry setup during completion mode
  • Add a completionHandler that provides content-aware completions for --group, --api, and --instance flags by reading values from fern.yml

Content-aware completion module (packages/cli/cli-v2/src/completion.ts)

  • Lightweight fern.yml parser that walks up from cwd and parses as plain YAML (no Zod validation, no $ref resolution) for speed
  • isCompletionMode() — detects when CLI is invoked for shell completion
  • getCompletionValues() — extracts group names (from sdks.targets[*].group[]), API names (from apis keys), and docs instance URLs (from docs.instances[*].url)
  • Falls back to default yargs completions for commands and other flags

Testing

  • pnpm run check (biome lint) passes
  • pnpm turbo run compile --filter @fern-api/cli-v2 compiles successfully
  • Manual review of yargs completion API compatibility

Link to Devin session: https://app.devin.ai/sessions/acbef1fddc974c579f764955a105160e
Requested by: @iamnamananand996

…ects

- Detect --get-yargs-completions in CLI v1 to suppress upgrade notices
  and skip version redirection during shell completion
- Add .completion() to CLI v2 with content-aware completions for
  --group, --api, and --instance flags (reads fern.yml)
- Skip telemetry initialization during completion mode for speed
@devin-ai-integration
Copy link
Copy Markdown
Contributor

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant