gte/cmd/cli/command/command.go

34 lines
564 B
Go
Raw Normal View History

2021-06-25 09:14:27 +02:00
package command
import (
"fmt"
"git.ewintr.nl/gte/internal/configuration"
)
type Command interface {
2021-07-09 09:42:44 +02:00
Do() string
2021-06-25 09:14:27 +02:00
}
func Parse(args []string, conf *configuration.Configuration) (Command, error) {
if len(args) == 0 {
return NewEmpty()
}
cmd, _ := args[0], args[1:]
switch cmd {
case "sync":
return NewSync(conf)
case "today":
return NewToday(conf)
2021-07-09 09:51:37 +02:00
case "tomorrow":
return NewTomorrow(conf)
2021-06-25 09:14:27 +02:00
default:
return NewEmpty()
}
}
2021-07-09 09:42:44 +02:00
func FormatError(err error) string {
return fmt.Sprintf("could not perform command.\n\nerror: %s\n", err.Error())
2021-06-25 09:14:27 +02:00
}