package main

import (
	"github.com/spf13/cobra"
	"github.com/spf13/viper"
)

var cfgFile string

var rootCmd = &cobra.Command{
	Use:   "metacrypt",
	Short: "Metacrypt cryptographic service",
	Long:  "Metacrypt is a cryptographic service for the Metacircular platform.",
}

func init() {
	cobra.OnInitialize(initConfig)
	rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default /srv/metacrypt/metacrypt.toml)")
}

func initConfig() {
	if cfgFile != "" {
		viper.SetConfigFile(cfgFile)
	} else {
		viper.SetConfigName("metacrypt")
		viper.SetConfigType("toml")
		viper.AddConfigPath(".")
		viper.AddConfigPath("/srv/metacrypt")
	}
	viper.AutomaticEnv()
	viper.SetEnvPrefix("METACRYPT")
	_ = viper.ReadInConfig()
}
