feat(cli): auth login + auth status commands (PR-4)
First two leaf commands and the auth/ command group, registered under the root command tree. auth login: - Email + password (interactive huh prompter) OR --with-token (read API key from stdin) for headless / CI use - Validates --host (required, must be http/https URL) - Persists access + refresh tokens (password mode) or api_key (token mode) into the secrets store wired in PR-3 — uses Store.Ref to record the URI scheme without leaking concrete backend type - Writes the named context to ~/.config/weknora/config.yaml and sets it as current_context - Typed loginResult payload for --json output (no map[string]any) auth status: - Calls client.GetCurrentUser -> /auth/me, prints context / host / user / tenant. --json emits a typed statusResult envelope with _meta.context and tenant_id populated for agents. - Service interface narrowed to just GetCurrentUser; tests inject fakes by overriding Factory.Client (no runF gymnastics). cmd/root.go: register \`auth\` parent under the root tree.
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
// Package auth holds the cobra commands for authentication
|
||||
// (login / status / logout / refresh). v0.0 ships login + status; logout
|
||||
// lands in v0.4 and refresh in v0.3.
|
||||
package auth
|
||||
|
||||
import (
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
"github.com/Tencent/WeKnora/cli/internal/cmdutil"
|
||||
)
|
||||
|
||||
// NewCmdAuth builds the `weknora auth` command tree and registers its
|
||||
// subcommands. Called from cli/cmd/root.go.
|
||||
func NewCmdAuth(f *cmdutil.Factory) *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "auth",
|
||||
Short: "Manage authentication credentials and contexts",
|
||||
// NoArgs makes cobra emit its canonical `unknown command "X" for
|
||||
// "weknora auth"` for any positional, which mapCobraError tags as
|
||||
// FlagError → exit 2. Run (not RunE) is required: a parent with
|
||||
// neither Run nor RunE short-circuits to help and skips Args
|
||||
// validation entirely.
|
||||
Args: cobra.NoArgs,
|
||||
Run: func(c *cobra.Command, _ []string) { _ = c.Help() },
|
||||
}
|
||||
cmd.AddCommand(NewCmdLogin(f, nil))
|
||||
cmd.AddCommand(NewCmdStatus(f))
|
||||
return cmd
|
||||
}
|
||||
Reference in New Issue
Block a user