Skip to content

fix(cmd): Hide full suggestions if they are aliases#401

Draft
craciunoiuc wants to merge 2 commits into
prod-stagingfrom
craciunoiuc/fix-completions
Draft

fix(cmd): Hide full suggestions if they are aliases#401
craciunoiuc wants to merge 2 commits into
prod-stagingfrom
craciunoiuc/fix-completions

Conversation

@craciunoiuc

@craciunoiuc craciunoiuc commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Closes: TOOL-1152
Closes: #399

Signed-off-by: Cezar Craciunoiu <cezar@unikraft.io>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adjusts the CLI’s tab-completion integration to hide redundant alias suggestions in root (and nested) command listings, while keeping aliases available when the user is typing a prefix. It introduces a small wrapper around kong-completion registration, adds targeted unit tests, and updates the README completion examples.

Changes:

  • Add registerCompletion wrapper to filter completion output and hide child-command aliases for “bare tab” completions.
  • Wire the new completion registration into the root command initialization, preserving the completion exit behavior.
  • Add unit tests for parsing COMP_LINE/COMP_POINT and for the alias-hiding completion behavior; update README completion invocation examples.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
README.md Updates shell completion script generation examples.
internal/cmd/root.go Switches from direct kongcompletion.Register to the new registerCompletion wrapper (with explicit exit handling).
internal/cmd/completion.go New implementation that captures/filters completion output to hide alias entries in root/nested listings.
internal/cmd/completion_test.go New tests covering COMP_LINE parsing and alias-hiding behavior during completion.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread internal/cmd/completion_test.go
Signed-off-by: Cezar Craciunoiu <cezar@unikraft.io>
@craciunoiuc craciunoiuc force-pushed the craciunoiuc/fix-completions branch from 6b2a7f0 to 6e4cb5d Compare July 6, 2026 19:25
Comment on lines +111 to +119
if isComp != tt.wantIsComp {
t.Fatalf("isCompletion = %v, want %v", isComp, tt.wantIsComp)
}
if !slices.Equal(completed, tt.wantCompleted) {
t.Errorf("completed = %v, want %v", completed, tt.wantCompleted)
}
if bareLast != tt.wantBareLast {
t.Errorf("bareLast = %v, want %v", bareLast, tt.wantBareLast)
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

testify.

Maybe add to AGENTS.md as well.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be worth mimicing the style here: https://github.com/unikraft/cli/blob/f0b830b56a8f6c2b40487cd3fddbdcd99e023d6d/internal/multimetro/key_test.go#L166-L166

That test style is quite clear and easy to verify, the current one here is a bit tricky to grok.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, I always assume it did it like the others and never actually check unit test generation 💫

// registerCompletion wires up kong-completion, the same way
// kongcompletion.Register does, but additionally hides command aliases from
// the root completion listing.
func registerCompletion(parser *kong.Kong, opt ...kongcompletion.Option) *int {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmmm. Is there a kongcompletion opt for this?

If not... is there something we could upstream that would make this more readable? I don't love needing to pull all the code of a dependency in, and run the completion ourself.

The upstream maintainer has actually been really receptive before.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is completion-enabled-command-alias.

Maybe that's okay honestly 🤔

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll try it out

@craciunoiuc craciunoiuc marked this pull request as draft July 7, 2026 15:07
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.

Incorrect autocompletion command info in README

3 participants