entry.go (838B)
1 package command 2 3 import ( 4 "errors" 5 "fmt" 6 "os" 7 "time" 8 9 "code.dwrz.net/src/pkg/dqs/command/help" 10 "code.dwrz.net/src/pkg/dqs/entry" 11 "code.dwrz.net/src/pkg/dqs/store" 12 ) 13 14 var Entry = &command{ 15 execute: func(args []string, date time.Time, store *store.Store) error { 16 u, err := store.GetUser() 17 if err != nil && !errors.Is(err, os.ErrNotExist) { 18 return fmt.Errorf("failed to get user: %w", err) 19 } 20 if u == nil { 21 return Config.execute(args, date, store) 22 } 23 24 e, err := store.GetEntry(date.Format(entry.DateFormat)) 25 if err != nil && !errors.Is(err, os.ErrNotExist) { 26 return fmt.Errorf("failed to get entry: %w", err) 27 } 28 if e == nil { 29 e = entry.New(date, u) 30 } 31 32 fmt.Println(e.FormatPrint(u)) 33 34 return nil 35 }, 36 37 description: "display a date's entry (default)", 38 help: help.Entry, 39 name: "entry", 40 }