feat(cli): add promote, cards, copy, demote, delete, edit commands

Complete CLI crystallization loop. Promote generates card_data
(template slots, checklist steps, link URLs). Cards view sorted by
use_count. Copy increments usage. Demote strips card layer. Delete
does soft then hard. Edit opens $EDITOR.
This commit is contained in:
2026-05-14 11:28:17 -04:00
parent a6fda5d1ee
commit c3cc9464b9
7 changed files with 431 additions and 2 deletions
+83
View File
@@ -0,0 +1,83 @@
package cmd
import (
"fmt"
"os"
"os/exec"
"github.com/lerko/nib/internal/db"
"github.com/lerko/nib/internal/display"
"github.com/spf13/cobra"
)
var editCmd = &cobra.Command{
Use: "edit <id>",
Short: "edit entity body in $EDITOR",
Args: cobra.ExactArgs(1),
RunE: runEdit,
}
func init() {
rootCmd.AddCommand(editCmd)
}
func runEdit(_ *cobra.Command, args []string) error {
store, err := openStore()
if err != nil {
return err
}
defer store.Close()
id, err := store.Resolve(args[0])
if err != nil {
return fmt.Errorf("not_found — no entity with id %s", args[0])
}
e, err := store.Get(id)
if err != nil {
return err
}
tmpfile, err := os.CreateTemp("", "nib-*.md")
if err != nil {
return err
}
defer os.Remove(tmpfile.Name())
if _, err := tmpfile.WriteString(e.Body); err != nil {
tmpfile.Close()
return err
}
tmpfile.Close()
editor := os.Getenv("EDITOR")
if editor == "" {
editor = "vi"
}
cmd := exec.Command(editor, tmpfile.Name())
cmd.Stdin = os.Stdin
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
if err := cmd.Run(); err != nil {
return fmt.Errorf("editor: %w", err)
}
newBody, err := os.ReadFile(tmpfile.Name())
if err != nil {
return err
}
body := string(newBody)
if body == e.Body {
fmt.Println("(no changes)")
return nil
}
if err := store.Update(id, &db.EntityUpdate{Body: &body}); err != nil {
return err
}
fmt.Printf("updated %s\n", display.FormatID(id))
return nil
}