Files
nib-v1/cmd/cards.go
T
lerko c3cc9464b9 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.
2026-05-14 11:28:17 -04:00

74 lines
1.3 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package cmd
import (
"fmt"
"strings"
"github.com/lerko/nib/internal/db"
"github.com/lerko/nib/internal/display"
"github.com/spf13/cobra"
)
var (
cardsTag string
cardsType string
)
var cardsCmd = &cobra.Command{
Use: "cards",
Short: "list crystallized cards by usage",
RunE: runCards,
}
func init() {
cardsCmd.Flags().StringVar(&cardsTag, "tag", "", "filter by tag")
cardsCmd.Flags().StringVar(&cardsType, "type", "", "filter by card type")
rootCmd.AddCommand(cardsCmd)
}
func runCards(_ *cobra.Command, _ []string) error {
store, err := openStore()
if err != nil {
return err
}
defer store.Close()
p := db.DefaultListParams()
p.CardsOnly = true
p.Sort = "use_count"
p.Order = "desc"
if cardsTag != "" {
p.Tag = &cardsTag
}
if cardsType != "" {
if !db.ValidCardType(cardsType) {
return fmt.Errorf("invalid_type — %q is not a valid card type", cardsType)
}
ct := db.CardType(cardsType)
p.CardTypeFilter = &ct
}
entities, err := store.List(p)
if err != nil {
return err
}
for _, e := range entities {
glyph := display.DisplayGlyph(e.Glyph, e.CardType)
shortID := display.FormatID(e.ID)
var tagStr string
for _, tag := range e.Tags {
tagStr += " #" + tag
}
fmt.Printf("%s %-40s %-16s %3d× %s\n",
glyph, e.Body,
strings.TrimSpace(tagStr),
e.UseCount, shortID)
}
return nil
}