feat(cli): --json field-select, --jq, auth token, doc --from-url
Output ergonomics:
- `--json` accepts a comma-separated field list (gh-parity); selects
named keys from the per-command payload. Bare `--json` keeps the
full shape.
- `--jq <expr>` evaluates a gojq expression over the JSON; pairs with
`--json field-list` so projection runs before jq.
- `--version` is a global cobra flag in addition to the `version`
subcommand; both render the same line.
- Per-command `--help` now renders the available JSON field list under
"JSON fields available via `--json id,name,...`" (field-discovery
parity with gh / kubectl `-o jsonpath`).
New commands:
- `auth token` — print the active context's credential to stdout for
shell command substitution (`WEKNORA_TOKEN=$(weknora auth token)`).
Default: raw secret, no trailing newline. `--json` emits
`{token, mode, context}`.
- `doc upload --from-url <URL>` — ingest a remote URL via the SDK
`CreateKnowledgeFromURL`. `--name` forwarded as `FileName` so the
server's known-extension heuristic upgrades crawl-mode to
file-download-mode where appropriate.
Includes the simplify post-review polish pass (field-filter unit
tests, --json/--jq compose check, agent_help copy fixes).
This commit is contained in:
@@ -52,7 +52,7 @@ func TestRunStatus_HumanOutput(t *testing.T) {
|
||||
&sdk.AuthTenant{ID: 7, Name: "Acme"},
|
||||
),
|
||||
}
|
||||
require.NoError(t, runStatus(context.Background(), &StatusOptions{}, f, svc))
|
||||
require.NoError(t, runStatus(context.Background(), nil, f, svc))
|
||||
got := out.String()
|
||||
assert.Contains(t, got, "context: prod")
|
||||
assert.Contains(t, got, "host: https://kb.example.com")
|
||||
@@ -69,14 +69,14 @@ func TestRunStatus_JSONOutput(t *testing.T) {
|
||||
}))
|
||||
f := &cmdutil.Factory{Config: func() (*config.Config, error) { return config.Load() }}
|
||||
svc := &fakeStatusService{resp: newCurrentUserResponse(&sdk.AuthUser{ID: "u1", Email: "a@b.c", TenantID: 7}, nil)}
|
||||
require.NoError(t, runStatus(context.Background(), &StatusOptions{JSONOut: true}, f, svc))
|
||||
require.NoError(t, runStatus(context.Background(), &cmdutil.JSONOptions{}, f, svc))
|
||||
assert.True(t, strings.HasPrefix(out.String(), `{"ok":true`), "got: %q", out.String())
|
||||
assert.Contains(t, out.String(), `"email":"a@b.c"`)
|
||||
}
|
||||
|
||||
func TestRunStatus_NoSDKClient(t *testing.T) {
|
||||
iostreams.SetForTest(t)
|
||||
err := runStatus(context.Background(), &StatusOptions{}, &cmdutil.Factory{}, nil)
|
||||
err := runStatus(context.Background(), nil, &cmdutil.Factory{}, nil)
|
||||
require.Error(t, err)
|
||||
assert.True(t, cmdutil.IsAuthError(err))
|
||||
}
|
||||
@@ -86,7 +86,7 @@ func TestRunStatus_SDKError_Transport(t *testing.T) {
|
||||
testutil.XDGTempDir(t)
|
||||
require.NoError(t, config.Save(&config.Config{CurrentContext: "p", Contexts: map[string]config.Context{"p": {Host: "https://x"}}}))
|
||||
f := &cmdutil.Factory{Config: func() (*config.Config, error) { return config.Load() }}
|
||||
err := runStatus(context.Background(), &StatusOptions{}, f, &fakeStatusService{err: assert.AnError})
|
||||
err := runStatus(context.Background(), nil, f, &fakeStatusService{err: assert.AnError})
|
||||
require.Error(t, err)
|
||||
// Non-HTTP errors (DNS / TCP) are transport problems, not auth problems —
|
||||
// classify network.error so retry logic / exit code 7 / IsTransient apply.
|
||||
@@ -98,7 +98,7 @@ func TestRunStatus_SDKError_HTTP401(t *testing.T) {
|
||||
testutil.XDGTempDir(t)
|
||||
require.NoError(t, config.Save(&config.Config{CurrentContext: "p", Contexts: map[string]config.Context{"p": {Host: "https://x"}}}))
|
||||
f := &cmdutil.Factory{Config: func() (*config.Config, error) { return config.Load() }}
|
||||
err := runStatus(context.Background(), &StatusOptions{}, f, &fakeStatusService{err: errors.New("HTTP error 401: invalid token")})
|
||||
err := runStatus(context.Background(), nil, f, &fakeStatusService{err: errors.New("HTTP error 401: invalid token")})
|
||||
require.Error(t, err)
|
||||
assert.True(t, cmdutil.IsAuthError(err))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user