app.go (767B)
1 package dqs 2 3 import ( 4 "time" 5 6 "code.dwrz.net/src/pkg/dqs/command" 7 "code.dwrz.net/src/pkg/dqs/store" 8 ) 9 10 type App struct { 11 store *store.Store 12 } 13 14 func New(cfg Config) (*App, error) { 15 if err := cfg.Validate(); err != nil { 16 return nil, err 17 } 18 19 store, err := store.Open(cfg.Dir) 20 if err != nil { 21 return nil, err 22 } 23 24 return &App{ 25 store: store, 26 }, nil 27 } 28 29 func (a *App) Run(args []string, date time.Time) error { 30 params := command.Parameters{ 31 Args: args, 32 Date: date, 33 Store: a.store, 34 } 35 36 // If no arguments were provided, print the entry. 37 if len(args) == 0 { 38 return command.Entry.Execute(params) 39 } 40 41 // Process the command. 42 params.Args = args[1:] 43 44 cmd, err := command.Match(args[0]) 45 if err != nil { 46 return err 47 } 48 49 return cmd.Execute(params) 50 }