WeKnora/cli/internal/cmdutil
nullkey 41a98b5743 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.
2026-05-14 10:57:17 +08:00
..
confirm.go feat(cli): add agent-first affordance — envelope, exit-10, --dry-run 2026-05-12 13:20:42 +08:00
dryrun.go feat(cli): add agent-first affordance — envelope, exit-10, --dry-run 2026-05-12 13:20:42 +08:00
errors.go refactor(cli): align command surface with mainstream conventions 2026-05-12 13:20:42 +08:00
errors_codes_test.go feat(cli): add internal/{text,compat} packages and acceptance scaffold (PR-6) 2026-05-09 12:18:01 +08:00
errors_test.go feat(cli): scaffold weknora CLI module foundation (PR-1) 2026-05-07 23:19:46 +08:00
exit.go refactor(cli): align command surface with mainstream conventions 2026-05-12 13:20:42 +08:00
exit_test.go feat(cli): scaffold weknora CLI module foundation (PR-1) 2026-05-07 23:19:46 +08:00
exporter.go chore(cli): remove unused v0.0 scaffolding 2026-05-12 13:20:42 +08:00
exporter_test.go chore(cli): remove unused v0.0 scaffolding 2026-05-12 13:20:42 +08:00
factory.go refactor(cli): align command surface with mainstream conventions 2026-05-12 13:20:42 +08:00
factory_test.go fix(cli): correct KB id detection, SSE terminal-frame, and CI test isolation 2026-05-12 13:20:42 +08:00
host.go feat(cli): context CRUD 2026-05-14 10:57:17 +08:00
kb.go fix(cli): correct KB id detection, SSE terminal-frame, and CI test isolation 2026-05-12 13:20:42 +08:00
options.go chore(cli): remove unused v0.0 scaffolding 2026-05-12 13:20:42 +08:00