Add shell auto-completion for commands and flags - #36
Merged
Conversation
Reviewer's GuideAdds centralized shell auto-completion helpers for clusters and nodes and wires them into relevant cobra commands and flags so that cluster names, node names, and control-plane nodes can be auto-completed in the CLI. Sequence diagram for CLI node name auto-completionsequenceDiagram
actor User
participant Shell
participant CobraCommand
participant CLICompletion as CLICompletion
participant PodmanClient
User->>Shell: Request completion for node flag/arg
Shell->>CobraCommand: Invoke completion callback
CobraCommand->>CLICompletion: CompleteNodeNames(cmd, args, toComplete)
CLICompletion->>PodmanClient: podman.NewClient()
CLICompletion->>PodmanClient: ContainerList(ctx, "label=bink.cluster-name=")
loop For each container
CLICompletion->>PodmanClient: ContainerInspect(ctx, ctr, "bink.component")
CLICompletion->>PodmanClient: ContainerInspect(ctx, ctr, "bink.node-name")
end
CLICompletion-->>CobraCommand: []string nodeNames, ShellCompDirectiveNoFileComp
CobraCommand-->>Shell: nodeNames
Shell-->>User: Present node name suggestions
File-Level Changes
Assessment against linked issues
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've found 1 issue, and left some high level feedback:
- The completion helpers all use
context.Background(); consider usingcmd.Context()instead so that completions respect cancellation/timeouts wired into the CLI context. - The three completion functions duplicate a fair amount of podman client and container-listing logic; extracting a shared helper (e.g., for listing cluster containers and pulling labels) would simplify maintenance and reduce the chance of inconsistent behavior across completions.
- The completion functions currently ignore the
toCompleteprefix and always return all candidates; filtering the returned names bytoCompletewould make completions more efficient and aligned with typical shell completion expectations.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The completion helpers all use `context.Background()`; consider using `cmd.Context()` instead so that completions respect cancellation/timeouts wired into the CLI context.
- The three completion functions duplicate a fair amount of podman client and container-listing logic; extracting a shared helper (e.g., for listing cluster containers and pulling labels) would simplify maintenance and reduce the chance of inconsistent behavior across completions.
- The completion functions currently ignore the `toComplete` prefix and always return all candidates; filtering the returned names by `toComplete` would make completions more efficient and aligned with typical shell completion expectations.
## Individual Comments
### Comment 1
<location path="internal/cli/completion.go" line_range="16-25" />
<code_context>
+ "github.com/bootc-dev/bink/internal/podman"
+)
+
+func CompleteClusterNames(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
+ client, err := podman.NewClient()
+ if err != nil {
+ return nil, cobra.ShellCompDirectiveNoFileComp
+ }
+
+ ctx := context.Background()
+ containers, err := client.ContainerList(ctx, "name="+config.ContainerNamePrefix)
+ if err != nil {
+ return nil, cobra.ShellCompDirectiveNoFileComp
+ }
+
+ seen := make(map[string]bool)
+ var names []string
+ for _, ctr := range containers {
+ clusterName, err := client.ContainerInspect(ctx, ctr, `{{index .Config.Labels "bink.cluster-name"}}`)
+ if err != nil || clusterName == "" {
+ continue
+ }
+ if !seen[clusterName] {
+ seen[clusterName] = true
+ names = append(names, clusterName)
+ }
+ }
+ return names, cobra.ShellCompDirectiveNoFileComp
+}
+
</code_context>
<issue_to_address>
**suggestion (performance):** Use cmd.Context() and honor the toComplete prefix in completion functions
These helpers currently use context.Background() and ignore toComplete. Please use cmd.Context() so completion respects CLI cancellation (e.g. SIGINT), and filter the returned names by toComplete to avoid unnecessary results, especially in clusters with many containers.
Suggested implementation:
```golang
package cli
import (
"context"
"strings"
"github.com/spf13/cobra"
"github.com/spf13/viper"
"github.com/bootc-dev/bink/internal/config"
"github.com/bootc-dev/bink/internal/podman"
)
```
```golang
ctx := cmd.Context()
```
```golang
if !seen[clusterName] && strings.HasPrefix(clusterName, toComplete) {
seen[clusterName] = true
names = append(names, clusterName)
}
```
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
alicefr
force-pushed
the
shell-out-completion
branch
from
May 29, 2026 07:36
e36ae15 to
f1b6792
Compare
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.
Fixes: #30
Summary by Sourcery
Add shell completion support for clusters and nodes across CLI commands.
New Features: