48 lines
897 B
Go
48 lines
897 B
Go
package cmd
|
|
|
|
import (
|
|
"os"
|
|
"path"
|
|
|
|
"git.maurice.fr/thomas/mailout/pkg/config"
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
var (
|
|
configFile string
|
|
cfg *config.Config
|
|
)
|
|
|
|
var RootCmd = &cobra.Command{
|
|
Use: "mailoutctl",
|
|
Short: "mailout management utility",
|
|
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
|
|
var err error
|
|
cfg, err = config.LoadConfig(configFile)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
},
|
|
}
|
|
|
|
func InitRootCmd() {
|
|
InitUserCmd()
|
|
InitDKIMKeyCmd()
|
|
InitTestCmd()
|
|
|
|
RootCmd.AddCommand(VersionCmd)
|
|
RootCmd.AddCommand(InitDBCmd)
|
|
RootCmd.AddCommand(UserCmd)
|
|
RootCmd.AddCommand(DKIMKeyCmd)
|
|
RootCmd.AddCommand(TestCmd)
|
|
|
|
homeDir, err := os.UserHomeDir()
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
defaultConfigFile := path.Join(homeDir, ".mailout.yml")
|
|
|
|
RootCmd.PersistentFlags().StringVarP(&configFile, "config", "c", defaultConfigFile, "Configuration file")
|
|
}
|