feat(cli): context CRUD
New v0.3 P0 entry 3-4: kubectl-style context-management subtree using gh's `<noun> <verb>` surface convention consistent with the rest of this CLI. - context list: tabwriter rendering + --json envelope; reads config.yaml only. - context add <name> --host <url> [--user]: validates http(s) URL, first context auto-becomes current, rejects duplicates with did-you-mean. - context remove <name>: best-effort keyring cleanup like `auth logout`. Removing the current context triggers exit-10 confirmation (lark-cli skill protocol) — subsequent commands would lose their default --context. (`context use` predates v0.3; the subtree was previously use-only.) Bugs caught and fixed inline by the post-commit reviewer round: - auth login was accepting `http://` (empty host portion) because the old validateHost only checked the scheme. New cmdutil.NormalizeHost (shared by both login and context add) requires u.Host != "". - context add's validateName claimed `..` was rejected but only denied / \\ space. Switched to positive allowlist [A-Za-z0-9._-] plus explicit ./../path-separator rejection. Helper consolidation: - cli/internal/cmdutil/host.go: NormalizeHost (trim, scheme, host non-empty) — both auth login and context add share it. - cli/internal/format/dash.go: DashIfEmpty — promoted from copies in cmd/auth/list.go and cmd/context/list.go. - recordingStore test stub dropped in favor of secrets.NewMemStore; contextKeyList test helper replaced by the existing contextKeys. 14 unit tests; 13 e2e branches verified. Roadmap: 3-4.
This commit is contained in:
@@ -1,5 +1,9 @@
|
||||
// Package contextcmd holds `weknora context` command tree (use; list / set /
|
||||
// delete in v0.4).
|
||||
// Package contextcmd holds `weknora context` command tree
|
||||
// (list / add / remove / use). Uses the gh-style `<noun> <verb>` shape
|
||||
// consistent with the rest of this CLI. kubectl exposes the same set
|
||||
// of operations as flat hyphenated subcommands (`config get-contexts /
|
||||
// set-context / delete-context / use-context`) — a different idiom we
|
||||
// don't adopt because it would make `context` an outlier in our tree.
|
||||
//
|
||||
// Package name `contextcmd` (not `context`) to avoid shadowing stdlib context.
|
||||
// The cobra Use: string is "context" — this is what users type.
|
||||
@@ -19,6 +23,9 @@ func NewCmd(f *cmdutil.Factory) *cobra.Command {
|
||||
Args: cobra.NoArgs,
|
||||
Run: func(c *cobra.Command, _ []string) { _ = c.Help() },
|
||||
}
|
||||
cmd.AddCommand(NewCmdList(f))
|
||||
cmd.AddCommand(NewCmdAdd(f))
|
||||
cmd.AddCommand(NewCmdRemove(f))
|
||||
cmd.AddCommand(NewCmdUse(f))
|
||||
return cmd
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user