2021-06-25 09:14:27 +02:00
|
|
|
package command
|
|
|
|
|
|
|
|
import (
|
2021-07-09 13:25:50 +02:00
|
|
|
"errors"
|
2021-06-25 09:14:27 +02:00
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"git.ewintr.nl/gte/internal/configuration"
|
|
|
|
)
|
|
|
|
|
2021-07-09 13:25:50 +02:00
|
|
|
var (
|
|
|
|
ErrInvalidAmountOfArgs = errors.New("invalid amount of args")
|
|
|
|
)
|
|
|
|
|
2021-06-25 09:14:27 +02:00
|
|
|
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()
|
|
|
|
}
|
|
|
|
|
2021-07-09 13:25:50 +02:00
|
|
|
cmd, cmdArgs := args[0], args[1:]
|
2021-06-25 09:14:27 +02:00
|
|
|
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-07-09 13:25:50 +02:00
|
|
|
case "new":
|
|
|
|
return NewNew(conf, cmdArgs)
|
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
|
|
|
}
|