Files
nib-v1/cmd/add.go
T
lerko f5b46585c3 feat: add title and description fields to capture grammar
Implement | prefix for titles and // separator for descriptions
across the full stack: parser, schema, API, CLI, and web frontend.

- Parser: line-aware extraction for |title, |title // desc,
  // leading desc, body // inline desc. URL-safe (skips :// lines).
  Modifiers (#tag, @time, ^card) extracted from all segments.
- Schema: ALTER TABLE migration adds title, description columns
- DB: Entity/EntityUpdate structs, all CRUD queries updated
- API: title/description on create/update/response, body validation
  relaxed (title-only entries valid)
- CLI: shows title as scan label when present
- Web: parseInput mirrors Go parser, list shows title, detail pane
  renders title + description with double-click inline editing
- Tests: 10 new cases (grammar, entity, API) — 71 total, all pass
2026-05-15 20:52:58 -04:00

77 lines
1.5 KiB
Go

package cmd
import (
"fmt"
"strings"
"github.com/lerko/nib/internal/db"
"github.com/lerko/nib/internal/display"
"github.com/lerko/nib/internal/parse"
"github.com/spf13/cobra"
)
var addCmd = &cobra.Command{
Use: "add [input]",
Short: "capture a new entity",
Args: cobra.MinimumNArgs(1),
RunE: runAdd,
}
func runAdd(_ *cobra.Command, args []string) error {
input := strings.Join(args, " ")
parsed, err := parse.Parse(input)
if err != nil {
return fmt.Errorf("parse: %w", err)
}
store, err := openStore()
if err != nil {
return err
}
defer store.Close()
e := &db.Entity{
Body: parsed.Body,
Title: parsed.Title,
Description: parsed.Description,
Glyph: db.Glyph(parsed.Glyph),
Tags: parsed.Tags,
}
if parsed.TimeAnchor != nil {
e.TimeAnchor = parsed.TimeAnchor
}
if parsed.CardSuffix != nil {
ct := db.CardType(*parsed.CardSuffix)
e.CardType = &ct
}
if err := store.Create(e); err != nil {
return err
}
glyph := display.DisplayGlyph(e.Glyph, e.CardType)
shortID := display.FormatID(e.ID)
var parts []string
parts = append(parts, glyph)
if e.Title != nil {
parts = append(parts, " "+*e.Title)
} else {
parts = append(parts, " "+e.Body)
}
if e.TimeAnchor != nil {
parts = append(parts, " @"+*e.TimeAnchor)
}
for _, tag := range e.Tags {
parts = append(parts, " #"+tag)
}
parts = append(parts, " ["+shortID+"]")
if e.CardType != nil {
parts = append(parts, fmt.Sprintf(" (%s)", *e.CardType))
}
fmt.Println(strings.Join(parts, ""))
return nil
}