package cli import ( "encoding/json" "fmt" "os" "github.com/spf13/cobra" "golang.org/x/term" "github.com/humdrum-tiv/dots-cli/internal/render" ) func NewTodayCmd() *cobra.Command { var date string var asJSON bool cmd := &cobra.Command{ Use: "today", Short: "Show the day grid", Args: cobra.NoArgs, RunE: func(cmd *cobra.Command, args []string) error { client, err := RequireClient() if err != nil { return err } if date == "" { date = Today() } isToday := date == Today() d, err := client.GetDay(date, TZ()) if err != nil { return err } if asJSON || !term.IsTerminal(int(os.Stdout.Fd())) { return json.NewEncoder(os.Stdout).Encode(map[string]any{ "date": date, "blockSize": d.BlockSize, "blocks": d.Blocks, "planBlocks": d.PlanBlocks, "types": d.Types, }) } current := -1 if isToday { now := timeNow() current = (now.Hour()*60 + now.Minute()) / d.BlockSize } fmt.Printf("%s\n\n", date) fmt.Print(render.Grid(d, current)) return nil }, } cmd.Flags().StringVar(&date, "date", "", "day to show (YYYY-MM-DD, default today)") cmd.Flags().BoolVar(&asJSON, "json", false, "raw JSON output") return cmd }