feat: add absorb command — merge source entity into target
DB: Absorb() merges body (newline-separated), unions tags, demotes
crystallized sources, soft-deletes source. Rejects crystallized targets.
API: POST /api/entities/:id/absorb { source_id }
CLI: nib absorb <target> <source> with prefix ID resolution
Web: absorb button on fluid entities, 'a' keyboard shortcut,
source picker modal
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/lerko/nib/internal/db"
|
||||
"github.com/lerko/nib/internal/display"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var absorbCmd = &cobra.Command{
|
||||
Use: "absorb <target> <source>",
|
||||
Short: "pull source material into target, ghost the source",
|
||||
Args: cobra.ExactArgs(2),
|
||||
RunE: runAbsorb,
|
||||
}
|
||||
|
||||
func init() {
|
||||
rootCmd.AddCommand(absorbCmd)
|
||||
}
|
||||
|
||||
func runAbsorb(_ *cobra.Command, args []string) error {
|
||||
store, err := openStore()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer store.Close()
|
||||
|
||||
targetID, err := store.Resolve(args[0])
|
||||
if err != nil {
|
||||
return fmt.Errorf("not_found — no entity with id %s", args[0])
|
||||
}
|
||||
|
||||
sourceID, err := store.Resolve(args[1])
|
||||
if err != nil {
|
||||
return fmt.Errorf("not_found — no entity with id %s", args[1])
|
||||
}
|
||||
|
||||
if targetID == sourceID {
|
||||
return fmt.Errorf("target and source must be different entities")
|
||||
}
|
||||
|
||||
if err := store.Absorb(targetID, sourceID); err != nil {
|
||||
if err == db.ErrTargetCrystallized {
|
||||
return fmt.Errorf("invalid_absorb — target %s is crystallized, demote first",
|
||||
display.FormatID(targetID))
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
fmt.Printf("absorbed %s → %s\n", display.FormatID(sourceID), display.FormatID(targetID))
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user