package main

import (
	"log"
	"os"

	"gopkg.in/urfave/cli.v1"
)

func main() {
	app := cli.NewApp()
	app.EnableBashCompletion = true
	app.Name = "crockery"
	app.Usage = "A vertically integrated, single-domain email system"
	app.Authors = []cli.Author{
		{Name: "Nick Thomas", Email: "crockery@ur.gs"},
	}

	app.Flags = []cli.Flag{
		cli.StringFlag{
			Name:   "db",
			Usage:  "Database file to use",
			EnvVar: "CROCKERY_DB",
			Value:  "crockery.db",
		},
	}

	app.Commands = []cli.Command{
		{
			Name:   "init",
			Usage:  "Create a new Crockery database",
			Action: crockeryInit,
			Flags: []cli.Flag{
				cli.StringFlag{
					Name:   "domain",
					Usage:  "Domain to serve email for",
					EnvVar: "CROCKERY_DOMAIN",
				},
				cli.StringFlag{
					Name:   "cert",
					Usage:  "File containing the PEM-encoded certificate bundle for the domain",
					EnvVar: "CROCKERY_CERT_FILE",
				},

				cli.StringFlag{
					Name:   "key",
					Usage:  "File containing the PEM-encoded private key for the domain",
					EnvVar: "CROCKERY_KEY_FILE",
				},
				cli.StringFlag{
					Name:   "postmaster-password",
					Usage:  "Password for the postmaster user",
					EnvVar: "CROCKERY_POSTMASTER_PASSWORD",
				},
			},
		},
		{
			Name:   "run",
			Usage:  "Run crockery",
			Action: crockeryRun,
		},
	}

	if err := app.Run(os.Args); err != nil {
		log.Fatal(err)
	}
}
