Files
nib-v1/cmd/add.go
T
lerko 97ad71d66b fix(parser): align Go and JS parsers with capture grammar spec
Kind prefixes now follow the canonical grammar: `-` for todo,
`@time` for event, `!time` for reminder. Removed `*`/`◇`/`▸`
as capture aliases (display-layer only). Added `\` escape prefix,
`?` query mode, `!pin` flag extraction, `##word` hash escape,
and tag lowercasing. Both parsers produce identical results.
2026-05-16 11:12:36 -04:00

78 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,
Pinned: parsed.Pin,
}
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
}