From e94b1311ded705b0af3a6977cf5fb248a9530387 Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Wed, 4 Dec 2019 18:30:01 +0100 Subject: Add basic theme support References: https://todo.sr.ht/~sircmpwn/koushin/1 --- cmd/koushin/main.go | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) (limited to 'cmd') diff --git a/cmd/koushin/main.go b/cmd/koushin/main.go index d30cb85..e644884 100644 --- a/cmd/koushin/main.go +++ b/cmd/koushin/main.go @@ -1,28 +1,41 @@ package main import ( + "flag" "fmt" - "os" "git.sr.ht/~emersion/koushin" + "github.com/labstack/echo/v4" "github.com/labstack/echo/v4/middleware" + "github.com/labstack/gommon/log" ) func main() { - if len(os.Args) != 2 && len(os.Args) != 3 { - fmt.Println("usage: koushin [SMTP URL]") - return + var options koushin.Options + flag.StringVar(&options.Theme, "theme", "", "default theme") + + flag.Usage = func() { + fmt.Fprintf(flag.CommandLine.Output(), "usage: koushin [options...] [SMTP URL]\n") + flag.PrintDefaults() } - imapURL := os.Args[1] + flag.Parse() - var smtpURL string - if len(os.Args) == 3 { - smtpURL = os.Args[2] + if flag.NArg() < 1 || flag.NArg() > 2 { + flag.Usage() + return } - e := koushin.New(imapURL, smtpURL) - e.Use(middleware.Logger()) + 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")) } -- cgit v1.2.3