feat(cli): scaffold weknora CLI module foundation (PR-1)
Empty cli/ Go module with Factory + Options skeleton that all v0.x commands plug into. Foundation packages (10 internal/): - cmdutil: Factory(3 closure: Config/Client/Prompter) + Options + Errors with namespaced ErrorCode + typed predicates (IsAuthError / IsNotFound / IsTransient / IsAuthExpired) + Exporter + AddJSONFlags + ExitCode/PrintError - iostreams: package singleton with TTY detection; ColorEnabled honors NO_COLOR / TERM=dumb on demand - agent: mode + detect + annotations (Stripe pkg/useragent pattern; CLAUDECODE / CURSOR_AGENT / CODEX_* / AIDER_* / CONTINUE_* / OPENCODE_* / GEMINICODER env detection) - build: ldflags-injected version/commit/date - safepaths: separator-aware path-traversal protection - config: yaml.v3 schema + atomic save 0600 (XDG-style) - format: success/failure envelope (code/hint/request_id/risk/retryable/ console_url) with typed RiskLevel - prompt: Prompter interface + AgentPrompter (rejects in agent mode) - secrets: file 0600 store with weknora:<context>:<key> namespace - testutil: XDGTempDir(t) test helper Smoke command: weknora version (-/--json). Build/test/vet matrix in .github/workflows/cli.yml across linux x macos x windows x Go 1.24. Factory.Client returns CodeLocalUnimplemented until PR-3 wires the SDK adapter; PR-1 commands (version) don't need it.
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
// Package build holds compile-time-injected build metadata.
|
||||
//
|
||||
// Values are set via -ldflags="-X github.com/Tencent/WeKnora/cli/internal/build.Version=..." at link time;
|
||||
// the Makefile's `version` target wires them up.
|
||||
package build
|
||||
|
||||
var (
|
||||
Version = "dev"
|
||||
Commit = "none"
|
||||
Date = "unknown"
|
||||
)
|
||||
|
||||
// Info returns a snapshot of the build metadata.
|
||||
func Info() (version, commit, date string) {
|
||||
return Version, Commit, Date
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package build
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestInfo_DefaultDevValues(t *testing.T) {
|
||||
v, c, d := Info()
|
||||
// In a non-ldflags-injected build, these are the package defaults; tests
|
||||
// that vary them need to assign at run time, not via -ldflags (testing
|
||||
// here only that Info returns whatever is current).
|
||||
assert.NotEmpty(t, v)
|
||||
assert.NotEmpty(t, c)
|
||||
assert.NotEmpty(t, d)
|
||||
}
|
||||
|
||||
func TestInfo_ReflectsInjectedValues(t *testing.T) {
|
||||
old := Version
|
||||
t.Cleanup(func() { Version = old })
|
||||
Version = "v0.0.0-test"
|
||||
v, _, _ := Info()
|
||||
assert.Equal(t, "v0.0.0-test", v)
|
||||
}
|
||||
Reference in New Issue
Block a user