mirror of
https://github.com/ditatompel/xmr-remote-nodes.git
synced 2024-12-22 11:39:23 +00:00
feat: Allow user to specify custom .env location
This feature can also be useful for running tests in CI.
This commit is contained in:
parent
6ba79cc00b
commit
e9cacb478c
3 changed files with 19 additions and 9 deletions
13
cmd/cmd.go
13
cmd/cmd.go
|
@ -3,12 +3,15 @@ package cmd
|
|||
import (
|
||||
"os"
|
||||
"xmr-remote-nodes/cmd/client"
|
||||
"xmr-remote-nodes/internal/config"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
const AppVer = "0.0.1"
|
||||
|
||||
var configFile string
|
||||
|
||||
var Root = &cobra.Command{
|
||||
Use: "xmr-nodes",
|
||||
Short: "XMR Nodes",
|
||||
|
@ -23,5 +26,15 @@ func Execute() {
|
|||
}
|
||||
|
||||
func init() {
|
||||
cobra.OnInitialize(initConfig)
|
||||
Root.PersistentFlags().StringVarP(&configFile, "config-file", "c", "", "Default to .env")
|
||||
Root.AddCommand(client.ProbeCmd)
|
||||
}
|
||||
|
||||
func initConfig() {
|
||||
if configFile != "" {
|
||||
config.LoadAll(configFile)
|
||||
return
|
||||
}
|
||||
config.LoadAll(".env")
|
||||
}
|
||||
|
|
|
@ -1,18 +1,17 @@
|
|||
package config
|
||||
|
||||
import (
|
||||
"log"
|
||||
"log"
|
||||
|
||||
"github.com/joho/godotenv"
|
||||
"github.com/joho/godotenv"
|
||||
)
|
||||
|
||||
// LoadAllConfigs set various configs
|
||||
func LoadAll(envFile string) {
|
||||
err := godotenv.Load(envFile)
|
||||
if err != nil {
|
||||
log.Fatalf("can't load .env file. error: %v", err)
|
||||
}
|
||||
if err := godotenv.Load(envFile); err != nil {
|
||||
log.Fatalf("can't load environment file. error: %v", err)
|
||||
}
|
||||
|
||||
LoadApp()
|
||||
LoadDBCfg()
|
||||
LoadDBCfg()
|
||||
}
|
||||
|
|
2
main.go
2
main.go
|
@ -2,10 +2,8 @@ package main
|
|||
|
||||
import (
|
||||
"xmr-remote-nodes/cmd"
|
||||
"xmr-remote-nodes/internal/config"
|
||||
)
|
||||
|
||||
func main() {
|
||||
config.LoadAll(".env")
|
||||
cmd.Execute()
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue