9aab79d49b
- Remove v1 Python CLI (src/kb_search/, tests/, root pyproject.toml, uv.lock, .venv) - Add Go client with cross-platform build (client/) - Add FastAPI engine with NVIDIA and multi-stage ROCm Dockerfiles (engine/) - Add VERSION files for client and engine, wired into builds - Add release.sh for automated build, tag, release, and Docker push - Update README with build/release docs and ROCm migration note - Clean up .gitignore for v2 project structure Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
85 lines
1.8 KiB
Go
85 lines
1.8 KiB
Go
package cmd
|
|
|
|
import (
|
|
"fmt"
|
|
"net/url"
|
|
"os"
|
|
|
|
"github.com/kb-search/kb/internal/api"
|
|
"github.com/kb-search/kb/internal/output"
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
var listCmd = &cobra.Command{
|
|
Use: "list",
|
|
Short: "List documents in the knowledge base",
|
|
RunE: runList,
|
|
}
|
|
|
|
func init() {
|
|
listCmd.Flags().String("type", "", "filter by document type")
|
|
listCmd.Flags().String("tags", "", "filter by tags (comma-separated)")
|
|
rootCmd.AddCommand(listCmd)
|
|
}
|
|
|
|
func runList(cmd *cobra.Command, args []string) error {
|
|
docType, _ := cmd.Flags().GetString("type")
|
|
tags, _ := cmd.Flags().GetString("tags")
|
|
|
|
params := url.Values{}
|
|
if docType != "" {
|
|
params.Set("type", docType)
|
|
}
|
|
if tags != "" {
|
|
params.Set("tags", tags)
|
|
}
|
|
|
|
path := "/api/v1/documents"
|
|
if len(params) > 0 {
|
|
path += "?" + params.Encode()
|
|
}
|
|
|
|
client := api.NewClient()
|
|
resp, err := client.Get(path)
|
|
if err != nil {
|
|
fmt.Fprintln(os.Stderr, err)
|
|
os.Exit(1)
|
|
}
|
|
if err := api.CheckError(resp); err != nil {
|
|
fmt.Fprintln(os.Stderr, err)
|
|
os.Exit(1)
|
|
}
|
|
|
|
if output.IsJSON() {
|
|
var raw interface{}
|
|
if err := api.DecodeJSON(resp, &raw); err != nil {
|
|
return fmt.Errorf("failed to decode response: %w", err)
|
|
}
|
|
output.PrintJSON(raw)
|
|
return nil
|
|
}
|
|
|
|
var docs []struct {
|
|
ID int `json:"id"`
|
|
Title string `json:"title"`
|
|
Type string `json:"doc_type"`
|
|
Tags []string `json:"tags"`
|
|
}
|
|
if err := api.DecodeJSON(resp, &docs); err != nil {
|
|
return fmt.Errorf("failed to decode response: %w", err)
|
|
}
|
|
|
|
if len(docs) == 0 {
|
|
fmt.Println("No documents found.")
|
|
return nil
|
|
}
|
|
|
|
headers := []string{"ID", "TITLE", "TYPE", "TAGS"}
|
|
var rows [][]string
|
|
for _, d := range docs {
|
|
rows = append(rows, []string{fmt.Sprintf("%d", d.ID), d.Title, d.Type, joinStrings(d.Tags)})
|
|
}
|
|
output.PrintTable(headers, rows)
|
|
return nil
|
|
}
|