package cmd import ( "fmt" "os" "github.com/kb-search/kb/internal/api" "github.com/kb-search/kb/internal/output" "github.com/spf13/cobra" ) var tagDescribeCmd = &cobra.Command{ Use: "tag-describe [description]", Short: "Set a one-line context description on a tag", Long: `Attach a short description to a tag (e.g. "Lab operations runbooks"). Descriptions are returned as tag_contexts with every search result on a document carrying the tag, helping consumers judge relevance. Omit the description (or pass "") to clear it.`, Args: cobra.RangeArgs(1, 2), RunE: runTagDescribe, } func init() { rootCmd.AddCommand(tagDescribeCmd) } func runTagDescribe(cmd *cobra.Command, args []string) error { description := "" if len(args) == 2 { description = args[1] } body := map[string]interface{}{"description": description} client := api.NewClient() resp, err := client.Put("/api/v1/tags/"+args[0]+"/description", 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) return nil } if description == "" { fmt.Printf("Description cleared for tag %q\n", args[0]) } else { fmt.Printf("Tag %q: %s\n", args[0], description) } return nil }