feat(completion): add 'ant completion <shell>' command#55
Open
EvanPaules wants to merge 3 commits into
Open
Conversation
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.
Author
|
Is there anyone who can review this? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
@completioncommand, 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
completionreturns 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.