Skip to content

completion: honor -p when listing VM names - #1218

Merged
cdalar merged 1 commit into
mainfrom
boxctl/zesty-fjord-0a05
Oct 22, 2026
Merged

cdalar merged 1 commit into
mainfrom
boxctl/zesty-fjord-0a05

Conversation

@cdalar

@cdalar cdalar commented Oct 22, 2026

Copy link
Copy Markdown
Owner

Problem

onctl -p ac delete <TAB> did not complete VM names. Cobra's completion path (__complete) parses flags but skips PersistentPreRunE, which was the only place -p/--provider was copied into ONCTL_CLOUD. So ensureProvider resolved the provider from the environment instead:

  • ONCTL_CLOUD unset: exits with "No Cloud Provider Set", no completions.
  • ONCTL_CLOUD set to another provider: completes that provider's VM names.

Exporting ONCTL_CLOUD=ac always worked, which made it look ac-specific.

Fix

Move the -p validation and ONCTL_CLOUD assignment into applyProviderFlag, called from both PersistentPreRunE and ensureProvider. This covers every completion that lists VMs or sizes: destroy and its aliases, ssh, port-forward, images, and the --type/--size size completions.

Verification

  • New TestEnsureProvider_HonorsProviderFlag: ONCTL_CLOUD=static with providerFlag = "ac" must build the ac provider. Fails on the old code, passes now.
  • End to end with a fake container CLI: onctl -p ac __complete delete "" returns the ac VM names with ONCTL_CLOUD unset and with it set to static; -p bogus returns the error directive.
  • go test ./cmd/ passes (one pre-existing, unrelated failure when run as root: TestPopulateOnctlEnv_ErrorWritingFile expects a read-only dir write to fail).

🤖 Generated with Claude Code

Cobra resolves ValidArgsFunction after parsing flags but without running
PersistentPreRunE, which was the only place -p/--provider was copied into
ONCTL_CLOUD. So `onctl -p ac destroy <TAB>` completed from ONCTL_CLOUD's
provider instead, or exited "No Cloud Provider Set" when it was unset.

Move the -p step into applyProviderFlag and call it from ensureProvider
too, so every completion that lists VMs or sizes (destroy and aliases,
ssh, port-forward, images, --type/--size) sees the flag.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@cdalar
cdalar enabled auto-merge (squash) October 22, 2026 05:36
@codecov

codecov Bot commented Oct 22, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 60.00000% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 45.70%. Comparing base (e171e43) to head (e002edf).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
cmd/root.go 60.00% 4 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1218      +/-   ##
==========================================
+ Coverage   45.57%   45.70%   +0.12%     
==========================================
  Files          75       75              
  Lines        8778     8783       +5     
==========================================
+ Hits         4001     4014      +13     
+ Misses       4777     4769       -8     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@cdalar
cdalar merged commit 121040e into main Oct 22, 2026
13 checks passed
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

⌂ 换网址