mailout/pkg/cmd/root.go
Thomas Maurice d08f82ba66
All checks were successful
build / build (push) Successful in 2m9s
feat(misc): allows user edition, templating of the home, and more
2024-02-14 18:50:35 +01:00

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")
}