aboutsummaryrefslogtreecommitdiff
path: root/cmd/koushin/main.go
blob: e6448849aeb5e28e62c62f4a902e836e724a19b3 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package main

import (
	"flag"
	"fmt"

	"git.sr.ht/~emersion/koushin"
	"github.com/labstack/echo/v4"
	"github.com/labstack/echo/v4/middleware"
	"github.com/labstack/gommon/log"
)

func main() {
	var options koushin.Options
	flag.StringVar(&options.Theme, "theme", "", "default theme")

	flag.Usage = func() {
		fmt.Fprintf(flag.CommandLine.Output(), "usage: koushin [options...] <IMAP URL> [SMTP URL]\n")
		flag.PrintDefaults()
	}

	flag.Parse()

	if flag.NArg() < 1 || flag.NArg() > 2 {
		flag.Usage()
		return
	}

	options.IMAPURL = flag.Arg(0)
	options.SMTPURL = flag.Arg(1)

	e := echo.New()
	if l, ok := e.Logger.(*log.Logger); ok {
		l.SetHeader("${time_rfc3339} ${level}")
	}
	if err := koushin.New(e, &options); err != nil {
		e.Logger.Fatal(err)
	}
	e.Use(middleware.Recover())
	e.Logger.Fatal(e.Start(":1323"))
}