manager/cmd/install.go

55 lines
1.3 KiB
Go

package cmd
import (
"context"
"code.icod.de/postfix/manager/ent"
_ "github.com/go-sql-driver/mysql"
"github.com/spf13/cobra"
)
var (
db string
setupPostfix bool
setupDovecot bool
)
// installCmd represents the install command
var installCmd = &cobra.Command{
Use: "install",
Short: "installs the database config files for postfix and creates the database",
RunE: func(cmd *cobra.Command, args []string) error {
// create database schema
client, e := ent.Open("mysql", "dev:dev@tcp(localhost:3306)/postfix")
if e != nil {
return e
}
defer client.Close()
ctx := context.Background()
if e := client.Schema.Create(ctx); e != nil {
return e
}
return nil
// setup postfix
},
}
func init() {
rootCmd.AddCommand(installCmd)
installCmd.Flags().BoolVar(&setupPostfix, "setup:postfix", true, "--setup:postfix=true|false")
installCmd.Flags().BoolVar(&setupPostfix, "setup:dovecot", true, "--setup:dovecot=true|false")
// Here you will define your flags and configuration settings.
// Cobra supports Persistent Flags which will work for this command
// and all subcommands, e.g.:
// installCmd.PersistentFlags().String("foo", "", "A help for foo")
// Cobra supports local flags which will only run when this command
// is called directly, e.g.:
// installCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
}