Add Tab Completion for Auth Context Names

we recently imported the entire auth contexts machinery from ~/src/entirehq/entiredb. I'm looking to add tab completion of context names. For some reason i can't find it in entiredb either. hm. search while i poke around further.
Bottom line
- It doesn't exist anywhere — not in entiredb either, because nobody wrote positional-arg completion. This codebase has zero
ValidArgsFunctionusages; the only completion in the whole CLI is flag completion viaRegisterFlagCompletionFunc(insearch_cmd.go). So there's nothing to "find" — it needs to be written. auth use <context>is the spot that wants it (cmd/entire/cli/auth_context.go:22, currently justArgs: cobra.ExactArgs(1)with no completion).- The enumerator already exists:
auth.Contexts()→([]*contexts.Context, currentName, error)atcmd/entire/cli/auth/context_store.go:114.
What to wire
The established pattern (from completeRepoFlag) but applied as a ValidArgsFunction instead of flag completion:
Mirrors the local conventions: swallow errors (completion runs on every TAB), ShellCompDirectiveNoFileComp, same func signature. Cobra auto-registers ValidArgsFunction — no separate RegisterFlagCompletionFunc call needed since it's a positional arg.
Two refinements worth deciding
- Cobra's
\tdescriptionconvention: you can appendname\tHandle (core URL)to each entry and it shows as completion help in zsh/fish. Could mark the current context too. - Optional: add the same
ValidArgsFunctionto any other command that takes<context>(e.g. aremove/deleteif one exists — the search only surfaceduse+contexts).
Want me to implement it (just use, with \t-descriptions and the current-context marker), and add a small test?
another task not to forget - i'd like to adjust the default context names. they should be 'handle@us.auth.<host>'. don't add \t-descriptions.
another task not to forget - i'd like to adjust the default context names. they should be 'handle@us.auth.<host>'. but sure, add \t-descriptions.
Completion is done and compiles. But the naming answers don't line up with what the code already does — I need to flag that before changing anything.
Bottom line
- Tab completion: done.
auth use <ctx>now completes stored context names withhandle coreURL (active)descriptions. Builds clean. - Naming change: blocked on a concrete example — your answers describe what the code already does.
The contradiction
Today, pickContextName (cmd/entire/cli/auth/contexts.go:126) already does, on collision:
And contextNameForCoreURL returns the full u.Host. So given core URL https://us.auth.entire.io, a collision already yields alice@us.auth.entire.io — which is exactly handle@us.auth.<host> with full host, on collision. Your three answers (derived-from-core-URL prefix + full host + collision-only) appear to already be the current behavior.
So one of these must be true, and I can't tell which from here:
- Core URLs don't contain
us.auth.today, and you want to inject it — i.e. transformcore.entire.io→us.auth.core.entire.io. That's the "derived" rule I'd need spelled out (where doesus.authcome from — region claim? fixed? a host rewrite?). - You actually want the
us.auth.<host>form as the bare default too (not just collision) — but you answered collision-only.
What I need
One concrete before→after, e.g.:
- core URL =
https://__________ - handle =
alice - desired name =
alice@us.auth.__________
Once you've got that from your poking-around, I'll wire the rule into pickContextName/contextNameForCoreURL and add a test. Want me to hold here?
oh, so if i login to us.auth.partial.to twice, the first will just be named us.auth.partial.to and the second will be alice@us.auth.partial.to? That's what i wanted, perfect. ensure the code matches that but then we're good.
Bottom line
- Tab completion: done.
auth use <ctx>completes stored context names withhandle coreURL (active)descriptions. Builds + vets clean. - Naming: already correct, already tested. No code change — current
pickContextNamegives first loginus.auth.partial.to, second identityalice@us.auth.partial.to, covered byTestRecordLoginContext_SameCoreDifferentHandlesCoexist. - Dropped the completion test — agreed, it was just re-asserting string formatting on thin glue.
Only change is cmd/entire/cli/auth_context.go (the ValidArgsFunction + completeContextNames helper). I didn't run mise run fmt/lint since you declined trusting the worktree's mise.toml — gofmt/go vet pass; run mise run check yourself when ready.