beads/cmd/bd/update_description_guard.go
beads/crew/emma f8152a1320 fix(update): require explicit opt-in for empty stdin/file DESCRIPTION rewrites
Guard against accidental description blanking when a producer fails but
still pipes empty input into bd update. Empty DESCRIPTION replacement
from --body-file, --description-file, --stdin, and dash shorthand now
requires --allow-empty-description. Inline --description "" unchanged.

Closes #2713

Co-Authored-By: Gary <gary@algorune.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-19 14:49:04 -07:00

48 lines
1.1 KiB
Go

package main
import (
"fmt"
"github.com/spf13/cobra"
)
func descriptionUsesExternalInput(cmd *cobra.Command) bool {
if stdinFlag, _ := cmd.Flags().GetBool("stdin"); stdinFlag {
return true
}
if cmd.Flags().Changed("body-file") || cmd.Flags().Changed("description-file") {
return true
}
if cmd.Flags().Changed("description") {
desc, _ := cmd.Flags().GetString("description")
if desc == "-" {
return true
}
}
if cmd.Flags().Changed("body") {
body, _ := cmd.Flags().GetString("body")
if body == "-" {
return true
}
}
if cmd.Flags().Changed("message") {
message, _ := cmd.Flags().GetString("message")
if message == "-" {
return true
}
}
return false
}
func validateDescriptionUpdate(cmd *cobra.Command, description string, descChanged bool) error {
if !descChanged || description != "" || !descriptionUsesExternalInput(cmd) {
return nil
}
allowEmptyDescription, _ := cmd.Flags().GetBool("allow-empty-description")
if allowEmptyDescription {
return nil
}
return fmt.Errorf("empty description from stdin/file requires --allow-empty-description (or use an explicit inline empty value like --description \"\")")
}