Skip to content

feat(completion): add 'ant completion <shell>' command#55

Open
EvanPaules wants to merge 3 commits into
anthropics:mainfrom
EvanPaules:feat/completion-command
Open

feat(completion): add 'ant completion <shell>' command#55
EvanPaules wants to merge 3 commits into
anthropics:mainfrom
EvanPaules:feat/completion-command

Conversation

@EvanPaules

Copy link
Copy Markdown

Add a user-facing ant completion <shell> command that prints a shell completion script to stdout. Supports bash, zsh, fish, and pwsh.

The completion-script renderer and the embedded shell-script templates were already shipping under the hidden @completion command, used by the release pipeline (.goreleaser.yml). This change makes that capability discoverable to end users via a single canonical surface.

Changes:

  • internal/autocomplete: add BuildCompletionCommand(appName) *cli.Command, the single source of truth for the completion command tree. Both production (pkg/cmd) and tests construct the command through this factory. Consolidates what were three near-identical "specify a shell" / "unsupported shell" error templates into one usageError helper.

  • pkg/cmd: register the command in cmd_completion.go (an 11-line shim matching the hand-written-command pattern of cmd_auth.go / cmd_profile.go). Remove the hidden @completion registration in cmd.go - the public command supersedes it.

  • .goreleaser.yml: invoke ant completion <shell> instead of @completion <shell> for the release-bundled completion scripts.

  • .gitattributes (new): force LF line endings on internal/autocomplete/shellscripts/* so Windows checkouts cannot introduce CRLF into the embedded scripts, which would break sourcing on Linux/macOS for binaries built from such checkouts.

  • internal/autocomplete/shellscripts/zsh_autocomplete.zsh: update an inline comment that referenced the removed @completion form.

  • internal/autocomplete/command_test.go (new): integration tests that drive the production factory directly - each shell renders correctly, bare completion returns a usage error, unknown shells return an error naming the supported set, and the renderer rejects unsupported shells with a usable message. Replaces the previous pkg/cmd/cmd_completion_test.go (its locally-defined helpers no longer exist after the consolidation).

Notes for reviewers:

  • The previously-hidden @completion command was renamed away rather than aliased, so the public surface is the only entry point. The hidden __complete runtime-completion command is unchanged.

  • pwsh is exposed publicly alongside bash/zsh/fish even though goreleaser only packages the latter three - this keeps one source of truth (SupportedShells in the autocomplete package). Restricting the public command set is a one-line filter if maintainers prefer.

  • urfave/cli's Suggest: true is set on the completion parent for consistency with sibling commands; on this command it governs only flag suggestions, not unknown-subcommand suggestions, because PrefixMatchCommands is not enabled. The hand-rolled usageError message is what users see for unknown shells.

Add a user-facing `ant completion <shell>` command that prints a shell
completion script to stdout. Supports bash, zsh, fish, and pwsh.

The completion-script renderer and the embedded shell-script templates
were already shipping under the hidden `@completion` command, used by
the release pipeline (.goreleaser.yml). This change makes that
capability discoverable to end users via a single canonical surface.

Changes:

- internal/autocomplete: add BuildCompletionCommand(appName) *cli.Command,
  the single source of truth for the completion command tree. Both
  production (pkg/cmd) and tests construct the command through this
  factory. Consolidates what were three near-identical "specify a shell"
  / "unsupported shell" error templates into one usageError helper.

- pkg/cmd: register the command in cmd_completion.go (an 11-line shim
  matching the hand-written-command pattern of cmd_auth.go / cmd_profile.go).
  Remove the hidden @completion registration in cmd.go - the public
  command supersedes it.

- .goreleaser.yml: invoke `ant completion <shell>` instead of
  `@completion <shell>` for the release-bundled completion scripts.

- .gitattributes (new): force LF line endings on
  internal/autocomplete/shellscripts/* so Windows checkouts cannot
  introduce CRLF into the embedded scripts, which would break sourcing
  on Linux/macOS for binaries built from such checkouts.

- internal/autocomplete/shellscripts/zsh_autocomplete.zsh: update an
  inline comment that referenced the removed @completion form.

- internal/autocomplete/command_test.go (new): integration tests that
  drive the production factory directly - each shell renders correctly,
  bare `completion` returns a usage error, unknown shells return an
  error naming the supported set, and the renderer rejects unsupported
  shells with a usable message. Replaces the previous
  pkg/cmd/cmd_completion_test.go (its locally-defined helpers no longer
  exist after the consolidation).

Notes for reviewers:

- The previously-hidden @completion command was renamed away rather
  than aliased, so the public surface is the only entry point. The
  hidden __complete runtime-completion command is unchanged.

- pwsh is exposed publicly alongside bash/zsh/fish even though
  goreleaser only packages the latter three - this keeps one source of
  truth (SupportedShells in the autocomplete package). Restricting the
  public command set is a one-line filter if maintainers prefer.

- urfave/cli's Suggest: true is set on the completion parent for
  consistency with sibling commands; on this command it governs only
  flag suggestions, not unknown-subcommand suggestions, because
  PrefixMatchCommands is not enabled. The hand-rolled usageError
  message is what users see for unknown shells.
@EvanPaules

Copy link
Copy Markdown
Author

Is there anyone who can review this?

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant