mailout/pkg/cmd/root.go

48 lines
896 B
Go

package cmd
import (
"fmt"
"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
},
}
var VersionCmd = &cobra.Command{
Use: "version",
Short: "Print the version number",
Long: ``,
Run: func(cmd *cobra.Command, args []string) {
fmt.Println("v0.0.1")
},
}
func InitRootCmd() {
InitUserCmd()
InitDKIMKeyCmd()
RootCmd.AddCommand(VersionCmd)
RootCmd.AddCommand(InitDBCmd)
RootCmd.AddCommand(UserCmd)
RootCmd.AddCommand(DKIMKeyCmd)
RootCmd.PersistentFlags().StringVarP(&configFile, "config", "c", "mailout.yml", "Configuration file")
}