Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ var walletFile string
var cDir string
var bSilent bool
var nonce int64
var configNotSet bool
var sourceFilePath string

// gTxnFee is the user specified fee passed from client/user.
// If the fee is absent/low it is adjusted to the min fee required
Expand Down Expand Up @@ -73,6 +75,7 @@ func Execute() {

func getConfigDir() string {
if cDir != "" {
configNotSet = false
return cDir
}
var configDir string
Expand All @@ -82,6 +85,7 @@ func getConfigDir() string {
fmt.Println(err)
os.Exit(1)
}
configNotSet = true
configDir = filepath.Join(home, "/.zcn")
return configDir
}
Expand Down Expand Up @@ -120,6 +124,7 @@ func loadConfigs() {
var configDir string

if cDir != "" {
configNotSet = false
configDir = cDir
} else {
configDir = getConfigDir()
Expand All @@ -130,6 +135,29 @@ func loadConfigs() {
if cfgFile != "" {
cfgConfig.SetConfigFile(filepath.Join(configDir, cfgFile))
} else {
if configNotSet {
// create a in .zcn directory and copy the default config file from the newtork directory
if _, err := os.Stat(configDir); os.IsNotExist(err) {
if err := os.Mkdir(configDir, 0777); err != nil {
ExitWithError("Can't create config directory:", err)
}
}
sourceFilePath = "./network/config.yaml"
sourceData, err := os.ReadFile(sourceFilePath)
if err != nil {
fmt.Println("Error reading source file:", err)
os.Exit(1)
}

err = os.WriteFile(filepath.Join(configDir, "config.yaml"), sourceData, 0777)
if err != nil {
fmt.Println("Error writing to destination file:", err)
os.Exit(1)
}

configNotSet = false

}
cfgConfig.SetConfigFile(filepath.Join(configDir, "config.yaml"))
}

Expand Down