src

Go monorepo.
git clone git://code.dwrz.net/src
Log | Files | Refs

export.go (698B)


      1 package command
      2 
      3 import (
      4 	"fmt"
      5 	"strings"
      6 	"time"
      7 
      8 	"code.dwrz.net/src/pkg/dqs/command/help"
      9 	"code.dwrz.net/src/pkg/dqs/store"
     10 )
     11 
     12 var Export = &command{
     13 	execute: func(args []string, date time.Time, store *store.Store) error {
     14 		entries, err := store.GetAllEntries()
     15 		if err != nil {
     16 			return err
     17 		}
     18 
     19 		var str strings.Builder
     20 		str.WriteString("date,body-fat,dqs,weight,\n")
     21 
     22 		for _, e := range entries {
     23 			str.WriteString(fmt.Sprintf(
     24 				"%s,%.2f,%.1f,%.2f,\n",
     25 				e.Date.Format("20060102"),
     26 				e.BodyFat,
     27 				e.Score(),
     28 				e.Weight,
     29 			))
     30 		}
     31 
     32 		fmt.Println(str.String())
     33 
     34 		return nil
     35 	},
     36 
     37 	description: "export entries to csv",
     38 	help:        help.Export,
     39 	name:        "export",
     40 }