Files
kb/client/cmd/tag.go
T
steve 9aab79d49b v2 restructure: Go client, Docker engine, release tooling
- 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>
2026-03-26 21:52:25 +00:00

76 lines
1.5 KiB
Go

package cmd
import (
"fmt"
"os"
"strings"
"github.com/kb-search/kb/internal/api"
"github.com/kb-search/kb/internal/output"
"github.com/spf13/cobra"
)
var tagCmd = &cobra.Command{
Use: "tag <id>",
Short: "Add or remove tags on a document",
Args: cobra.ExactArgs(1),
RunE: runTag,
}
func init() {
tagCmd.Flags().String("add", "", "tags to add (comma-separated)")
tagCmd.Flags().String("remove", "", "tags to remove (comma-separated)")
rootCmd.AddCommand(tagCmd)
}
func runTag(cmd *cobra.Command, args []string) error {
addStr, _ := cmd.Flags().GetString("add")
removeStr, _ := cmd.Flags().GetString("remove")
body := map[string]interface{}{}
if addStr != "" {
body["add"] = splitTags(addStr)
}
if removeStr != "" {
body["remove"] = splitTags(removeStr)
}
if len(body) == 0 {
return fmt.Errorf("specify --add and/or --remove")
}
client := api.NewClient()
resp, err := client.Put("/api/v1/documents/"+args[0]+"/tags", body)
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)
} else {
fmt.Printf("Tags updated for document %s\n", args[0])
}
return nil
}
func splitTags(s string) []string {
var tags []string
for _, t := range strings.Split(s, ",") {
t = strings.TrimSpace(t)
if t != "" {
tags = append(tags, t)
}
}
return tags
}