Skip to content

Fix: allow completion command to run without an Octopus login#612

Draft
HuyPhanNguyen wants to merge 1 commit into
mainfrom
huy/2026/fd-555-cli-completion-not-logged-in
Draft

Fix: allow completion command to run without an Octopus login#612
HuyPhanNguyen wants to merge 1 commit into
mainfrom
huy/2026/fd-555-cli-completion-not-logged-in

Conversation

@HuyPhanNguyen

Copy link
Copy Markdown
Contributor

Background

octopus completion <shell> is a local Cobra command that prints a shell completion script; it never contacts the server. But commandDoesNotRequireClient in cmd/octopus/main.go doesn't include it, so when the user hasn't run octopus login the client factory fails to build and the CLI exits with code 3, printing the config banner to stdout instead of the script. Piping that into Invoke-Expression then fails with The term 'Work' is not recognized. The same gap hits Cobra's hidden __complete/__completeNoDesc helpers, which the shell calls on every Tab press — so completions stay broken when not logged in even after installing them.

Results

Adds completion, __complete, and __completeNoDesc to commandDoesNotRequireClient so completion works without a login.

Fixes FD-555
Fixes #611

Before

Not logged in:

$ octopus completion powershell
Work seamlessly with Octopus Deploy from the command line.
... (banner) ...
# exit code 3, nothing on stderr

octopus completion powershell | Out-String | Invoke-ExpressionThe term 'Work' is not recognized.

After

Not logged in:

$ octopus completion powershell
# powershell completion for octopus ...
Register-ArgumentCompleter -CommandName 'octopus' -ScriptBlock $__octopusCompleterBlock
# exit code 0

octopus __complete "" also returns the command list (exit 0) instead of failing.

Testing

  • Added a unit test covering the completion commands in commandDoesNotRequireClient.
  • Manually verified against a build: unauthenticated completion powershell and __complete now exit 0; the ... | Out-String | Invoke-Expression command runs clean.

Note: this fixes the not-logged-in failure only. A separate report that tab-completion doesn't fire in Windows PowerShell 5.1 (when logged in) is not addressed here.

The completion command and cobra's __complete/__completeNoDesc helpers
require a client factory, so shell completion fails with exit 3 when the
user is not logged in. Add them to commandDoesNotRequireClient since they
are purely local and never contact the server.
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.

octopus completion powershell returns root help/banner instead of PowerShell completion script (exit code 3)

1 participant