ce335cabd6
Stream/cards toggle with 1/2 keys. Cards view with intent filtering (tab cycles grab/read/fill/all), sort cycling (s key), pinned-first ordering, and affordance badges. Promote picker (p key) with card type selection and auto-detection from body content. Detail view renders card_data per type: checklist steps, template slots, decision fields, link URLs. Extracts generateCardData to internal/carddata for reuse across cmd and tui packages.
61 lines
1.2 KiB
Go
61 lines
1.2 KiB
Go
package cmd
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/lerko/nib/internal/carddata"
|
|
"github.com/lerko/nib/internal/db"
|
|
"github.com/lerko/nib/internal/display"
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
var promoteCmd = &cobra.Command{
|
|
Use: "promote <id> [type]",
|
|
Short: "promote a fluid entity to a card",
|
|
Args: cobra.RangeArgs(1, 2),
|
|
RunE: runPromote,
|
|
}
|
|
|
|
func init() {
|
|
rootCmd.AddCommand(promoteCmd)
|
|
}
|
|
|
|
func runPromote(_ *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])
|
|
}
|
|
|
|
cardType := db.CardSnippet
|
|
if len(args) > 1 {
|
|
if !db.ValidCardType(args[1]) {
|
|
return fmt.Errorf("invalid_type — %q is not a valid card type", args[1])
|
|
}
|
|
cardType = db.CardType(args[1])
|
|
}
|
|
|
|
e, err := store.Get(id)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
cd := carddata.GenerateCardData(cardType, e.Body)
|
|
|
|
if err := store.Promote(id, cardType, cd); err != nil {
|
|
if err == db.ErrAlreadyPromoted {
|
|
return fmt.Errorf("invalid_promote — entity %s is already a %s",
|
|
display.FormatID(id), *e.CardType)
|
|
}
|
|
return err
|
|
}
|
|
|
|
fmt.Printf("promoted %s → %s\n", display.FormatID(id), cardType)
|
|
return nil
|
|
}
|