Skip to content

auth: act on the context named as the argument to switch and remove - #2084

Open
DO-rrao wants to merge 4 commits into
mainfrom
fix/auth-switch-remove-context-arg
Open

DO-rrao wants to merge 4 commits into
mainfrom
fix/auth-switch-remove-context-arg

Conversation

@DO-rrao

@DO-rrao DO-rrao commented Oct 28, 2026

Copy link
Copy Markdown
Contributor

Shell completion has offered context names as the argument to doctl auth switch and doctl auth remove since #1044, but neither command ever read an argument; they only look at --context. So accepting a suggestion did the wrong thing:

$ doctl auth switch microdroplet-preview
Notice: Now using context [default] by default     # stayed on default

$ doctl auth remove microdroplet-preview
Error: You must provide a context name

The silent no-op on switch was first reported in #659. A customer hit it again recently.

Changes

  • switch and remove take the context as their argument, as well as with --context. Naming two different contexts, or passing more than one argument, is an error.
  • Context completion lists default once (it was suggested twice once default was in auth-contexts) and the rest in sorted order (they came from a map, so the order changed between presses). Names are no longer suggested after --context has been given.
  • init, login, list and token no longer fall back to completing file names.
  • Help, examples and the README show doctl auth switch <name> / doctl auth remove <name>.

Testing

  • New unit tests: TestAuthSwitchAndRemoveTakeContextArgument, TestGetAuthContextList.
  • go test ./commands/ -run 'TestAuth|TestGetAuthContextList|Test_displayAuthContexts' and go test ./integration/ -run 'TestRun/doctl/auth' pass.
  • Manually against a copy of a real config:
Command Result
auth switch microdroplet-preview switches, config updated
auth switch --context microdroplet-preview still works
auth switch microdroplet-preview --context default error: context given twice
auth switch a b error: unsupported arguments
auth remove microdroplet-preview context deleted
__complete auth switch "" default, microdroplet-preview (once each)
__complete auth token "" no file completion

Shell completion has offered context names as the argument to
`doctl auth switch` and `doctl auth remove` since #1044, but neither
command read it. `doctl auth switch work` reported "Now using context
[default]" and left the current context in place; `doctl auth remove
work` failed with "You must provide a context name".

Both commands now take the context as their argument as well as with
--context. Naming two different contexts, or passing more than one
argument, is an error.

Completion also lists each context once and in a stable order, and the
auth commands that take no argument no longer complete file names.

Co-authored-by: Cursor <cursoragent@cursor.com>
@SSharma-10

Copy link
Copy Markdown
Contributor

the usage strings switch and remove read as if the name is required in that position. Square brackets would match how these commands actually behave: switch [name] and remove [name].

doctl auth switch works with no name and keeps the current context, and both commands still accept --context. The long help already explains that

DO-rrao and others added 3 commits November 2, 2026 16:05
The name can be omitted when --context is set, and switch with neither keeps the current context.

Co-authored-by: Cursor <cursoragent@cursor.com>
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.

2 participants