moved remote commands to cli
This commit is contained in:
parent
928270059a
commit
1218e99450
|
@ -9,7 +9,10 @@ import (
|
|||
|
||||
var (
|
||||
ErrInvalidAmountOfArgs = errors.New("invalid amount of args")
|
||||
ErrInvalidArg = errors.New("invalid argument")
|
||||
ErrCouldNotFindTask = errors.New("could not find task")
|
||||
ErrFieldAlreadyUsed = errors.New("field was already used")
|
||||
ErrUnknownFolder = errors.New("unknown folder")
|
||||
)
|
||||
|
||||
type Command interface {
|
||||
|
@ -42,6 +45,8 @@ func Parse(args []string, conf *configuration.Configuration) (Command, error) {
|
|||
return NewFolder(conf, cmdArgs)
|
||||
case "add":
|
||||
return NewAdd(conf, cmdArgs)
|
||||
case "remote":
|
||||
return parseRemote(conf, cmdArgs)
|
||||
default:
|
||||
return NewEmpty()
|
||||
}
|
||||
|
@ -64,3 +69,18 @@ func parseTaskCommand(id int, tArgs []string, conf *configuration.Configuration)
|
|||
return NewShow(id, conf)
|
||||
}
|
||||
}
|
||||
|
||||
func parseRemote(conf *configuration.Configuration, cmdArgs []string) (Command, error) {
|
||||
switch {
|
||||
case len(cmdArgs) < 1:
|
||||
cmd, _ := NewEmpty()
|
||||
return cmd, ErrInvalidAmountOfArgs
|
||||
case cmdArgs[0] == "recur":
|
||||
return NewRecur(conf, cmdArgs[1:])
|
||||
case cmdArgs[0] == "inbox":
|
||||
return NewInbox(conf)
|
||||
default:
|
||||
cmd, _ := NewEmpty()
|
||||
return cmd, ErrInvalidArg
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package command
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"strings"
|
||||
|
||||
"git.ewintr.nl/gte/cmd/cli/format"
|
||||
|
@ -11,10 +10,6 @@ import (
|
|||
"git.ewintr.nl/gte/internal/task"
|
||||
)
|
||||
|
||||
var (
|
||||
ErrUnknownFolder = errors.New("unknown folder")
|
||||
)
|
||||
|
||||
type Folder struct {
|
||||
lister *process.List
|
||||
}
|
||||
|
|
|
@ -0,0 +1,32 @@
|
|||
package command
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"git.ewintr.nl/gte/cmd/cli/format"
|
||||
"git.ewintr.nl/gte/internal/configuration"
|
||||
"git.ewintr.nl/gte/internal/process"
|
||||
"git.ewintr.nl/gte/internal/storage"
|
||||
"git.ewintr.nl/gte/pkg/mstore"
|
||||
)
|
||||
|
||||
type Inbox struct {
|
||||
inboxer *process.Inbox
|
||||
}
|
||||
|
||||
func NewInbox(conf *configuration.Configuration) (*Inbox, error) {
|
||||
remote := storage.NewRemoteRepository(mstore.NewIMAP(conf.IMAP()))
|
||||
|
||||
return &Inbox{
|
||||
inboxer: process.NewInbox(remote),
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (i *Inbox) Do() string {
|
||||
res, err := i.inboxer.Process()
|
||||
if err != nil {
|
||||
return format.FormatError(err)
|
||||
}
|
||||
|
||||
return fmt.Sprintf("processed %d tasks\n", res.Count)
|
||||
}
|
|
@ -0,0 +1,43 @@
|
|||
package command
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
|
||||
"git.ewintr.nl/gte/cmd/cli/format"
|
||||
"git.ewintr.nl/gte/internal/configuration"
|
||||
"git.ewintr.nl/gte/internal/process"
|
||||
"git.ewintr.nl/gte/internal/storage"
|
||||
"git.ewintr.nl/gte/pkg/msend"
|
||||
"git.ewintr.nl/gte/pkg/mstore"
|
||||
)
|
||||
|
||||
type Recur struct {
|
||||
recurrer *process.Recur
|
||||
}
|
||||
|
||||
func NewRecur(conf *configuration.Configuration, cmdArgs []string) (*Recur, error) {
|
||||
remote := storage.NewRemoteRepository(mstore.NewIMAP(conf.IMAP()))
|
||||
disp := storage.NewDispatcher(msend.NewSSLSMTP(conf.SMTP()))
|
||||
|
||||
if len(cmdArgs) < 1 {
|
||||
return &Recur{}, ErrInvalidAmountOfArgs
|
||||
}
|
||||
daysAhead, err := strconv.Atoi(cmdArgs[0])
|
||||
if err != nil {
|
||||
return &Recur{}, ErrInvalidArg
|
||||
}
|
||||
|
||||
return &Recur{
|
||||
recurrer: process.NewRecur(remote, disp, daysAhead),
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (r *Recur) Do() string {
|
||||
res, err := r.recurrer.Process()
|
||||
if err != nil {
|
||||
return format.FormatError(err)
|
||||
}
|
||||
|
||||
return fmt.Sprintf("generated %d tasks\n", res.Count)
|
||||
}
|
|
@ -1,7 +1,6 @@
|
|||
package command
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
|
@ -13,10 +12,6 @@ import (
|
|||
"git.ewintr.nl/gte/pkg/msend"
|
||||
)
|
||||
|
||||
var (
|
||||
ErrFieldAlreadyUsed = errors.New("field was already used")
|
||||
)
|
||||
|
||||
type Update struct {
|
||||
updater *process.Update
|
||||
}
|
||||
|
|
|
@ -1,42 +0,0 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"os"
|
||||
|
||||
"git.ewintr.nl/go-kit/log"
|
||||
"git.ewintr.nl/gte/internal/configuration"
|
||||
"git.ewintr.nl/gte/internal/process"
|
||||
"git.ewintr.nl/gte/internal/storage"
|
||||
"git.ewintr.nl/gte/pkg/msend"
|
||||
"git.ewintr.nl/gte/pkg/mstore"
|
||||
)
|
||||
|
||||
func main() {
|
||||
logger := log.New(os.Stdout).WithField("cmd", "generate-recurring")
|
||||
|
||||
configPath := flag.String("c", "~/.config/gte/gte.conf", "path to configuration file")
|
||||
daysAhead := flag.Int("d", 6, "generate for this amount of days from now")
|
||||
flag.Parse()
|
||||
|
||||
configFile, err := os.Open(*configPath)
|
||||
if err != nil {
|
||||
logger.WithErr(err).Error("could not open config file")
|
||||
os.Exit(1)
|
||||
}
|
||||
config := configuration.New(configFile)
|
||||
|
||||
msgStore := mstore.NewIMAP(config.IMAP())
|
||||
mailSend := msend.NewSSLSMTP(config.SMTP())
|
||||
taskRepo := storage.NewRemoteRepository(msgStore)
|
||||
taskDisp := storage.NewDispatcher(mailSend)
|
||||
recur := process.NewRecur(taskRepo, taskDisp, *daysAhead)
|
||||
|
||||
result, err := recur.Process()
|
||||
if err != nil {
|
||||
logger.WithErr(err).Error("unable to process recurring")
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
logger.WithField("result", result).Info("finished generating recurring tasks")
|
||||
}
|
|
@ -1,35 +0,0 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"os"
|
||||
|
||||
"git.ewintr.nl/go-kit/log"
|
||||
"git.ewintr.nl/gte/internal/configuration"
|
||||
"git.ewintr.nl/gte/internal/process"
|
||||
"git.ewintr.nl/gte/internal/storage"
|
||||
"git.ewintr.nl/gte/pkg/mstore"
|
||||
)
|
||||
|
||||
func main() {
|
||||
logger := log.New(os.Stdout).WithField("cmd", "process-inbox")
|
||||
|
||||
configPath := flag.String("c", "~/.config/gte/gte.conf", "path to configuration file")
|
||||
flag.Parse()
|
||||
|
||||
configFile, err := os.Open(*configPath)
|
||||
if err != nil {
|
||||
logger.WithErr(err).Error("could not open config file")
|
||||
os.Exit(1)
|
||||
}
|
||||
config := configuration.New(configFile)
|
||||
msgStore := mstore.NewIMAP(config.IMAP())
|
||||
inboxProcessor := process.NewInbox(storage.NewRemoteRepository(msgStore))
|
||||
|
||||
result, err := inboxProcessor.Process()
|
||||
if err != nil {
|
||||
logger.WithErr(err).Error("unable to process inbox")
|
||||
os.Exit(1)
|
||||
}
|
||||
logger.WithField("result", result).Info("finished processing inbox")
|
||||
}
|
Loading…
Reference in New Issue