trustless-generic-relayer/offchain-relayer/main.go

63 lines
1.4 KiB
Go

package main
import (
"fmt"
"os"
"github.com/spf13/cobra"
"github.com/spf13/viper"
"github.com/certusone/generic-relayer/offchain-relayer/relay"
)
var cfgFile string
// rootCmd represents the base command when called without any subcommands
var rootCmd = &cobra.Command{
Use: "offchain-relayer",
Short: "Wormhole relayer for multichain dapp",
}
// main adds all child commands to the root command and sets flags appropriately.
func main() {
if err := rootCmd.Execute(); err != nil {
fmt.Println(err)
os.Exit(1)
}
}
func init() {
cobra.OnInitialize(initConfig)
rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is {pwd}/.relayer.yaml)")
rootCmd.AddCommand(relay.RelayCmd)
}
// initConfig reads in config file and ENV variables if set.
func initConfig() {
if cfgFile != "" {
// Use config file from the flag.
viper.SetConfigFile(cfgFile)
} else {
// Find home directory.
wd, err := os.Getwd()
if err != nil {
fmt.Println(err)
os.Exit(1)
}
fmt.Println(wd)
// Search config in working directory with name ".relayer" (without extension).
viper.AddConfigPath(wd)
viper.SetConfigName(".relayer")
}
viper.AutomaticEnv() // read in environment variables that match
// If a config file is found, read it in.
if err := viper.ReadInConfig(); err == nil {
fmt.Println("Using config file:", viper.ConfigFileUsed())
}
}