Add Tab Completion for Auth Context Names · Entire

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

What to wire

The established pattern (from completeRepoFlag) but applied as a ValidArgsFunction instead of flag completion:

// in newAuthUseCmd(), on the &cobra.Command{...}
ValidArgsFunction: completeContextNames,

func completeContextNames(_ *cobra.Command, args []string, _ string) ([]string, cobra.ShellCompDirective) {
    if len(args) != 0 { // only complete the first positional
        return nil, cobra.ShellCompDirectiveNoFileComp
    }
    ctxs, _, err := auth.Contexts()
    if err != nil {
        return nil, cobra.ShellCompDirectiveNoFileComp
    }
    names := make([]string, 0, len(ctxs))
    for _, c := range ctxs {
        names = append(names, c.Name)
    }
    return names, cobra.ShellCompDirectiveNoFileComp
}

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

Want me to implement it (just use, with \t-descriptions and the current-context marker), and add a small test?

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

The contradiction

Today, pickContextName (cmd/entire/cli/auth/contexts.go:126) already does, on collision:

host := contextNameForCoreURL(coreURL) // = u.Host, the FULL core-URL host
qualified := handle + "@" + host       // → handle@<full-host>

And contextNameForCoreURL returns the fullu.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:

  1. Core URLs don't contain us.auth. today, and you want to inject it — i.e. transform core.entire.io → us.auth.core.entire.io. That's the "derived" rule I'd need spelled out (where does us.auth come from — region claim? fixed? a host rewrite?).
  2. 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.:

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.

Now fmt + lint on the touched tree.

Bottom line

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.